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 sulas · Mar 05, 2010 at 07:55 PM · textyield

making LateUpdate wait for Fade in/out guiText

Hi,

I am trying to display something like a subtitle, the guiText.text changes at certain seconds.

What I am having trouble with is, I can not fade the guiText out - change it - fade it back in. I am pretty sure there is a very simple way to do this, I have looked into yield, coroutines and tried everything I could think of. Here is what I have:

function LateUpdate () {

  seconds=GameObject.Find("Timer").GetComponent("Timer").seconds;


switch(seconds){

 case 0:
 fadeOut();
 fadeIn();
 print("second 0");
 guiText.text="Lascia Chi'o Pianga";


 break;

 case 6:
 print("6th second");
 fadeOut();
 fadeIn();
 guiText.text="Mia Crudo, Sorte";
 break;

 default:
 //guiText.text=guiText.text;
 break;


}

and of course the fadeIn and fadeOut functions

function fadeIn(){

 guiText.material.color.a=Mathf.Lerp(0,1,Time.time);
 yield WaitForSeconds(1);

}

function fadeOut(){ guiText.material.color.a=Mathf.Lerp(1,0,Time.time); yield WaitForSeconds(1);

}

What I was hoping for was, that the yield WaitForSeconds statements would interrupt the LateUpdate. What happens is that, the first line fades in perfectly, stays on screen, then when case 6 is true, the second line kicks in instantly.

So, the first FadeIn works, the rest doesn't? I am not sure what is going on.

Thanks in advance :)

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

1 Reply

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

Answer by Eric5h5 · Mar 05, 2010 at 08:26 PM

You can't interrupt Update or LateUpdate at all; they always run every frame. For scheduling a series of events, you are better off forgetting about Update and using coroutines instead. One problem is that Mathf.Lerp uses the range of 0 to 1 for the third parameter, so your fade in and out functions will only work during the first second that Unity is running.

As a side note, GameObject.Find is slow, so doing that in Update is not optimal. It should be done once in Start or Awake, and the result cached. Actually I'm not sure you need the Timer script at all...using the Fade script in the wiki, I would do this:

function Start () { FadeOutIn("Lascia Chi'o Pianga"); yield WaitForSeconds(6.0); FadeOutIn("Mia Crudo, Sorte"); }

function FadeOutIn (s : String) { yield Fade.use.Alpha (guiText.material, 1.0, 0.0, 1.0); guiText.text = s; yield Fade.use.Alpha (guiText.material, 0.0, 1.0, 1.0); }

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 sulas · Mar 05, 2010 at 08:46 PM 0
Share

Thank you Eric5h5, this works great, it saved me a lot of time :) I did not know of this script in the wiki.

avatar image agentsmith · Jul 02, 2010 at 12:55 AM 0
Share

This really helped me out too!! Great work!!

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

No one has followed this question yet.

Related Questions

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

How do i make a TextArea Descend when messages happen 0 Answers

Need help with appearing text on the trigger 1 Answer

Input a string and the computer answers with a command? 4 Answers

Making Credits Scroll Upwards on Screen 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