• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by Peterw301 · Nov 13, 2012 at 05:04 PM · javascriptguitexttouch

The gui disappears when i let go

Ive made a script so when i click an object like an npc i can talk to it with different responses but when i go to touch the responses the GUI goes i would like it so when i let go, The GUI stays till i press the close button :). Any help would be greatly appreciated

  var target : Transform;
 
 function OnGUI () {
 ///making a varible i named it position it has to hav a lowercase first letter ive made it equal to a 2d position space by putting Vector2 and the (x,y) is the place im ref    var position = Vector2(0,0);
 /// mr cubies position is (x = 6.14779,y = 1)
 
 
    var screenPosX : Vector3 = camera.WorldToScreenPoint (target.position);
     print ("target is " + screenPosX.x + " pixels from the left");      
           
         for (var touch : Touch in Input.touches) {
         if (touch.phase == TouchPhase.Stationary) { 
     
     
     var touchPositionXRounded = Mathf.Round(touch.position.x / 100);
     var touchPositionYRounded = Mathf.Round(touch.position.y / 100);
   // screen position of gameobject  
      var screenPosY : Vector3 = camera.WorldToScreenPoint (target.position);
          print ("target is " + screenPosY.y + " pixels from the top");
     
     var oSPX = Mathf.Round(screenPosX.x / 100);
     var oSPY = Mathf.Round(screenPosY.y / 100);
         
     
 
 ///        Debug.Log(touch.position);
         Debug.Log(touchPositionXRounded);
         Debug.Log(touchPositionYRounded);
         Debug.Log(oSPX);
         Debug.Log(oSPY);
 // if touch position = the touch position of game object display a gui box
         if (touchPositionXRounded ==  oSPX){
         if (touchPositionYRounded ==  oSPY) {
         
         GUI.Box(Rect(10,10,100,90),"Hello");
         if (GUI.Button(Rect(10,80,100,90),"Close")) {
            touch == false;
         }
 // if you click the button it displays a gui text box over the old one        
         if (GUI.Button(Rect(120,10,150,40),"Hi")){ 
             GUI.Box(Rect(10,10,100,90),"Hello");
         
         }
         
         if (GUI.Button(Rect(120,60,150,40),"Go away!")){
             GUI.Box(Rect(10,10,100,90),"fine then moody :(");
         
         }
        
        
        }
     }
   }
 }
 }



EDIT i added a boolean but still does not work :(

 #pragma strict
 
 var show :  boolean;
 var show2 : boolean;
 var target : Transform;
 
    var screenPosX : Vector3 = camera.WorldToScreenPoint (target.position);
     print ("target is " + screenPosX.x + " pixels from the left");      
    var screenPosY : Vector3 = camera.WorldToScreenPoint (target.position);
     print ("target is " + screenPosY.y + " pixels from the top");
     
   // screen position of gameobject  
    
     var oSPX = Mathf.Round(screenPosX.x / 100);
     var oSPY = Mathf.Round(screenPosY.y / 100);
 if(show2 === true);
 {
   
 }
 function Update () {
  
  for (var touch : Touch in Input.touches) {
  if (touch.phase == TouchPhase.Began) {
  show = true;
  Debug.Log("niceballsTrue");
  Debug.Log(show);
     
     var touchPositionXRounded = Mathf.Round(touch.position.x / 100);
     var touchPositionYRounded = Mathf.Round(touch.position.y / 100);
 }
 else
 {
  show = false;
   Debug.Log("False");
   Debug.Log(show);
 }
 
 
 
 
 if(show === true)
 {
    Debug.Log("OMG IT WORKSish");
 }
 else if (touchPositionXRounded == oSPX) 
 {
    if (touchPositionYRounded ==  oSPY) {
         show2 = true;
        }
    Debug.Log("ITS ALIVE":)
 }
 else
 {
    Debug.Log("printed false :(");
   }
  }
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SolidSnake · Nov 13, 2012 at 05:27 PM 1
Share
avatar image AlucardJay · Nov 13, 2012 at 05:38 PM 1
Share
avatar image Peterw301 · Nov 14, 2012 at 06:53 PM 0
Share

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by joeyaaaaa · Feb 03, 2013 at 09:43 AM

i t$$anonymous$$nk you just need to
add somet$$anonymous$$ng like

if (GUIbox == 1) { GUI.Box(Rect(10,10,100,90),"Hello"); if (GUI.Button(Rect(10,80,100,90),"Close")) { touch == false; } }

// if you click the button it displays a gui text box over the old one
if (GUI.Button(Rect(120,10,150,40),"Hi")){

          GUIbox = 0
         GUI.Box(Rect(10,10,100,90),"Hello");
     }
     if (GUI.Button(Rect(120,60,150,40),"Go

away!")){ GUI.Box(Rect(10,10,100,90),"fine then moody :(");

after reading a few times tbh i am unsure of your question, but to make it stay say guibox = 1 lol

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Peterw301 · Feb 04, 2013 at 07:20 PM 0
Share
avatar image joeyaaaaa · Feb 04, 2013 at 07:49 PM 0
Share
avatar image
0

Answer by Peterw301 · Feb 04, 2013 at 09:37 PM

My code is very confusing basically I didn't know about OnMouseDown() so my version of it was to get the position of the touch then divide it by 100 so it was less accurate to confiscate for big hands. So when you clicked a GUI box came up and you could put responses.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing 3d text through script 1 Answer

Move the text in a GUI Button/Box 1 Answer

Gui Text Script 4 Answers

Playing multiple sounds with multiple subtitles 1 Answer

GUIText Problem With MENU 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges