Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by kohenb · Aug 08, 2011 at 01:23 PM · iphonefirst-person-controllergui.box

Making a GUI text disappear with a tap, FPS look around with finger

Hi, I have this script, which when a specific object is tapped, it creates a nice GUI textbox. The issue is, I then want the textbox to disappear when tapped, or when the screen is tapped elsewhere. I've had no luck in figuring it out.

var turret: GameObject; private var showBox = false; var boxwidth: int = 300; var boxheight: int = 300; var boxfromleft: int = 500; var boxfromright: int = 500;

function Update () {

 for (var touch : Touch in Input.touches) {
     if (touch.phase == TouchPhase.Began) {
     
     var ray = Camera.main.ScreenPointToRay (touch.position);
     
     if (Physics.Raycast (ray)) {
         showBox = true;
         
         }
     }
 }

}

function OnGUI () { if (showBox)

 GUI.Box (Rect (boxfromleft,boxfromright,boxwidth,boxheight), "A classic Neo-Victorian Turret");
 
 }
 

Also, I also I have been trying to get a first person look around script, that when a camera in enabled in the first person view, dragging a finger around the screen allows you to look around. I've tried modifying the first person iPhone controls, to just have the right side joystick working because thats all I need.

Any help is much appreciated! Thanks K.

Comment
Add comment
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

2 Replies

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

Answer by Blankzz · Aug 08, 2011 at 02:09 PM

My answer is related to your first question. Maybe you should split your questions into two posts. Anyway..... Have you tried storing the textbox rectangle and using Rect.contains to see if the mouse is within the textboxs' rectangle or out of the rectangle when the mouse is pressed or finger taps? Look at http://unity3d.com/support/documentation/ScriptReference/Rect.Contains.html

Edit: Try this code and check logging to see what is happening

 var rect = Rect(boxfromleft,boxfromright,boxwidth,boxheight);
 
 if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) 
 { 
     if (showBox == false)
     {
         var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position); 
         var hit: RaycastHit; 
         
         if(Physics.Raycast (ray,hit,10000) && hit.collider.gameObject.tag == "rightturret")
         {
             showBox = true;
             Debug.Log("Box should be displayed");
         }
     }
     else
     {
         if  (!rect.Contains(Input.GetTouch(0).position))
         {
             showBox = false;
             Debug.Log("Box should be hidden");
         }
     }
 }
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 kohenb · Aug 09, 2011 at 12:10 PM 0
Share

That seems logical, but for some reason when I execute the code, Unity is telling me that 'touch' is and unknown identifier. So something to do with the "Rect.Contains(touch.position)" line.

avatar image kohenb · Aug 09, 2011 at 07:18 PM 0
Share

Worked Wonderfully. I noted the addition to the "if (showBox == false)" statement earlier in the block of code, because indeed before it worked I was getting, errors related to the Boolean.

Thanks very much for your help, I'll organize my code better next time as well! $$anonymous$$

avatar image
0

Answer by kohenb · Aug 09, 2011 at 04:07 PM

function Update () {

var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position); var hit: RaycastHit; if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { if (Physics.Raycast (ray,hit,10000)) if (hit.collider.gameObject.tag == "rightturret") { showBox = true;

             var rect = Rect(boxfromleft,boxfromright,boxwidth,boxheight);
             if (rect.Contains(Input.GetTouch(0).position)) 
                 {
                 showBox = false;
             }   
         }
     }
 }

I've updated to the following code, with no errors, however it will not make the GUI.box disappear yet. Thoughts?

Thanks again for your input! K.

Comment
Add comment · Show 1 · 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 Blankzz · Aug 09, 2011 at 05:53 PM 0
Share

Could you make sure your code is formatted correctly before posting. I'm now going to update my post with code that I think is better. I'm not sure why its not disappearing but lets try troubleshoot.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Lighting not working on iOS device with fpc 0 Answers

How to use FirstPersonController script for iPhone? 2 Answers

iphone/ipad Gyro perpendiculat and moving FPC 1 Answer

Switching between FPS and Relative during play? 1 Answer

Controller for iPhone 2 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