Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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

Could you please edit your question and highlight your code part?

avatar image AlucardJay · Nov 13, 2012 at 05:38 PM 1
Share

As Solid Snake said : for further help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

Though, it may be easier just to delete the code, paste it in again from the source, then highlight all the code and press the 101010 button at the top of the edit window before posting.

you could remove the swearing too

avatar image Peterw301 · Nov 14, 2012 at 06:53 PM 0
Share

Sorry alucardj, and thank you Both was struggling with that :)

2 Replies

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

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

i think you just need to
add something 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

Yea I've sorted it now thx i set every thing in a update function so the gui was only staying for the frame it was clicked :/ I can't remember it all but the problem was fixed simply thx for answering this I put it up ages ago. The unity community is constantly surprising me! Sorry that it was unclear I am only thirteen everything I learnt was from the Internet. Thank you for answering this question after so long :D

avatar image joeyaaaaa · Feb 04, 2013 at 07:49 PM 0
Share

no worries, and i misread alot of posts, your post was clear lol and i didnt realize it was an old post, it was high on the list ^^ yw. good luck!

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.

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

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

Create GUIText from Javascript 3 Answers

How to make GUI Text appear after a certain amount of time 2 Answers

touch 3d object open gui 1 Answer

iPhone GUI Text asks for edit on touch 0 Answers


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