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 RamboPanda · Sep 07, 2011 at 04:24 AM · guiios

Turning GUI off not working for iOS

Hello. I'm trying to get my GUI to off after 3 seconds but it's not working. My GUI stays on all the time after hitting the cube. I tried to use the yield statement in the OnGUI function but it ends up turning the GUI off entirely. How do I off it after a certain amount of time? Thank you.

Here's my code:

 #pragma strict
 
 var showGUI = false;
 
 var otherScript : PlayerRelativeControl;
 var increase = 5.0;
 var temporarySpeed = 0.0; 
 var speedBoostDuration = 4;
 var nextActivationTime = 0.0;
 
 private var timer = 0.0;
 private var horizontalSpeed = Input.GetAxis("Horizontal");
 private var verticalSpeed = Input.GetAxis("Vertical");
 
 function Update()
 {
 
     rigidbody.mass = 0.1;
     var otherScript = GetComponent(PlayerRelativeControl);
     
 }
 
 function OnControllerColliderHit (collisionObject: ControllerColliderHit)
 { 
     if(collisionObject.gameObject.name == "Cube" && Time.time > nextActivationTime) 
     { 
         
         nextActivationTime = Time.time + speedBoostDuration;
         Destroy(collisionObject.gameObject); 
         
             temporarySpeed = otherScript.forwardSpeed +increase;
             showGUI  = true;
             yield WaitForSeconds(3);
             temporarySpeed = otherScript.forwardSpeed;
         
         
         rigidbody.AddTorque(Vector3(0,horizontalSpeed,verticalSpeed) * 10); 
         rigidbody.AddForce (Vector3(temporarySpeed,0,0));
         
         showGUI = false;
         
     } 
     
     
 }
 
     
 function OnGUI () 
 {
     if(showGUI)
     {
     
         GUI.enabled = showGUI;
         GUI.Label (Rect (Screen.width/2, Screen.height/3, 600, 40), "Speed Increase!");
         
     }
 
 }

Thank you. Cheers.

Comment
Add comment · Show 4
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 Eric5h5 · Sep 07, 2011 at 05:14 AM 0
Share

Why are you setting rigidbody.mass to .1 and doing "var otherScript = GetComponent(PlayerRelativeControl);" every frame in Update? Especially since you're not even using that variable for anything.

avatar image RamboPanda · Sep 07, 2011 at 05:30 AM 0
Share

I thought that would help to connect the 2 scripts together.

avatar image Eric5h5 · Sep 07, 2011 at 05:37 AM 0
Share

In what way? You're declaring a variable that you're not using, every frame.

avatar image RamboPanda · Sep 07, 2011 at 07:44 AM 0
Share

Okay I have taken out the function. But the GUI ("Speed Increase") still stays there after 3 secs.

1 Reply

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

Answer by aldonaletto · Sep 07, 2011 at 01:38 PM

I tested this script in my PC, and it produced some runtime errors; when I fixed them, it worked fine. The errors were:

1- You should remove var from the line where you get otherScript via GetComponent - this keyword was creating a temporary variable, so the public otherScript never was assigned. By the way, you should place this code in Start, since it only needs to be executed once;
2- You must move both Input.GetAxis to the Update function (or any other). Input.GetAxis outside any function produces a runtime error.
All the changes were situated at the same region, so I show below only the modified part of the code:

... private var timer = 0.0; private var horizontalSpeed: float; private var verticalSpeed: float;

function Start(){ rigidbody.mass = 0.1; otherScript = GetComponent(PlayerRelativeControl); }

function Update(){ horizontalSpeed = Input.GetAxis("Horizontal"); verticalSpeed = Input.GetAxis("Vertical"); } ...

Comment
Add comment · Show 5 · 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 aldonaletto · Sep 07, 2011 at 02:26 PM 0
Share

Ooops! I forgot to declare the types of horizontalSpeed and verticalSpeed. Answer fixed now.

avatar image RamboPanda · Sep 08, 2011 at 01:40 AM 0
Share

Hello! it works fine now but the GUI (""Speed Increase!" ) did not turn off after the speed went back to the default speed. What should I do? Thank you so much for helping!! :)

avatar image RamboPanda · Sep 08, 2011 at 05:31 AM 0
Share

Hello! I have managed to solve the problem by setting another function to enable the showGUI to true, yield for 3 seconds and offed it after that. Thank you for your help! :)) Cheers!!

avatar image aldonaletto · Sep 08, 2011 at 12:23 PM 0
Share

The mistery persists: Speed Increase turned off in my PC after 3 seconds, as expected. Could it be some iOS version bug? God knows! Anyway, what really matters is that you solved the problem.

avatar image RamboPanda · Sep 09, 2011 at 01:21 AM 0
Share

goodness gracious... i'm not sure. i'm currently using the trial version of Unity Pro. :) thanks a lot!! cheers! :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Trigger a GUI when tapping and object in IOS 1 Answer

Find the Vector to divert from colliding? 1 Answer

Is it possible to link character skill lists to a GUI, and if so, how? 3 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