• 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
Question by c.zeta · Dec 08, 2011 at 04:41 PM · guiyielddelayonenableondisable

delayed function problem

I have 2 scripts attached to 2 different objects, when the first object becomes visible the second script whit my GUI is enabled, when the first object disappears, I want to close my GUI. The problem is that when the GUI is closed I can't see the animations of the buttons in it because there's no time to show them. This is my code, maybe it explains my problem better:

first script:

 var otherScript : guifinal;

 if (renderer.isVisible) {
 
     otherScript.enabled = true;
 
     }
 else {
     DisableRendererWithDelay();
     }
 }
 
 function DisableRendererWithDelay() {
     yield WaitForSeconds(2);
     otherScript.enabled = false;
 }

second script:

     function OnEnable(){
     
     iTween.ValueTo(gameObject,iTween.Hash("from",CurrentButtonSize(),"to",buttonVertSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",.3));
     iTween.ValueTo(gameObject,iTween.Hash("from",VertButtonSize(),"to",buttonOrizSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",1));
 
 }    
 
 function OnDisable(){
     
     iTween.ValueTo(gameObject,iTween.Hash("from",CurrentButtonSize(),"to",buttonNormalSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",.2));
 
 }

 

There is a way to send instantly the trigger of "otherScript.enabled = true" but execute it after 2 seconds?

Comment

People who like this

0 Show 1
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 funkyllama · Dec 08, 2011 at 06:55 PM 0
Share

The problem I see with that is you do a yield WaitForSeconds(2) and then disable, so the OnDisable() in the second script gets called after 2 seconds.. You'll need to use a boolean in your second script that can be called before the yield, then that boolean triggers your tween before the object gets disabled.. See below

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by funkyllama · Dec 08, 2011 at 06:49 PM

You could try something like this ..
In your second script:
Add a boolean variable, something like 'disabling : boolean = false'
Then rename your OnDisable() function to Disable() and add disabling = false

 function Disable(){
     iTween.ValueTo(gameObject,iTween.Hash("from",CurrentButtonSize(),"to",buttonNormalSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",.2));
     disabling = false;    
 }


Add an if statement in the update function of your second script

 if(disabling) {  
     disable();  
 }

In your first script:
just before you do your yield WaitForSeconds(2); add the line
otherScript.disabling = true;

Hope this makes sense :)

Comment

People who like this

0 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 c.zeta · Dec 08, 2011 at 07:06 PM 0
Share

thank you so much, this was driving me mad, now is quite working (I have undestand the method, now I'm trying to apply correctly).. but I don't understand why also the OnEnable function starts after 2 seconds

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Gui label delay 1 Answer

Have a function wait unitl a boolean is false 1 Answer

How to delay a respawn? 1 Answer

Delay when reloading 0 Answers

Why is yield not working for me? 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