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
0
Question by paulaceccon · Dec 23, 2012 at 09:38 PM · coroutinetimeguitexture

Using coroutine to change current GUI

Hi, as the title try to say, I have to change my GUI, specifically, a GUITexture, from time to time. For example: in the first 5 seconds, I have to display the GUITexture1. After this, for another 5 seconds, I have to show the GUITexture2. I intend to display this GUITextures to make something like a "Introduction".

So, I've tried to do something like this:

 void OnGUI ()
 {    
     if (messageGUI)
     {
           if (textOpt == "Ligado")
          {
             message = Resources.Load("Levels/General/generalSpeech1") as Texture;
             StartCoroutine(showMessage(message, new Vector2(tabItem, Screen.height-avatarSize-2*tabItem-messageSize.y), messageSize, time));
                 
             message = Resources.Load("Levels/General/generalSpeech2") as Texture;
             StartCoroutine(showMessage(message, new Vector2(tabItem, Screen.height-avatarSize-2*tabItem-messageSize.y), messageSize, time));
                 
             message = Resources.Load("Levels/General/generalSpeech3") as Texture;
             StartCoroutine(showMessage(message, new Vector2(tabItem, Screen.height-avatarSize-2*tabItem-messageSize.y), messageSize, time));
             }
         }
     }
 
 IEnumerator showMessage (Texture message, Vector2 position, Vector2 size, float time)
 {
     messageGUI.enabled = true;
     messageGUI.texture = message;
     messageGUI.name = "Message";
     messageGUI.pixelInset = new Rect(position.x, position.y, size.x, size.y);
     yield return new WaitForSeconds(time);
     messageGUI.enabled = false;
 }

But I've noted that this don't solve my problem, 'cause the OnGUI function are always running and the next command don't wait the previous to finish before starts running. I know why, but I don't figure out how could I do what I want. Any ideas?

Thanks in advance.

Comment
Add comment · 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 asafsitner · Dec 23, 2012 at 11:19 PM 1
Share

I suppose implementing your own timers with Time.deltaTime should work.

1 Reply

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

Answer by paulaceccon · Dec 26, 2012 at 04:33 PM

Yeah, thks @asafsitner, and @cawas, for helping even outside the forum.

I could solve my problem with this script:

 void Update(){
         
     introduction ();
         
     if(displayMessage){
         Debug.Log(timer+" "+currentMessage);
         timer += Time.deltaTime;
         if(timer <= time){
             messageGUI.enabled = true;
             messageGUI.texture = message;
             messageGUI.pixelInset = new Rect(position.x, position.y, messageSize.x, messageSize.y);
         }
         else
         {
                messageGUI.enabled = false;    
             displayMessage = false;
             timer = 0f;
             currentMessage ++;
         }
     }
 }
     
 //Levels
 void introduction ()
 {    
     if (textOpt == "Ligado")
     {
         if (currentMessage == 1)
         {
             message = Resources.Load("Levels/General/generalSpeech1") as Texture;
             position = new Vector2(tabItem, Screen.height-avatarSize-2*tabItem-messageSize.y);
             displayMessage = true;    
         }
         else if (currentMessage == 2)
         {
             message = Resources.Load("Levels/General/generalSpeech2") as Texture;
             position = new Vector2(tabItem, Screen.height-avatarSize-2*tabItem-messageSize.y);
             displayMessage = true;    
         }
         else if (currentMessage == 3)
         {
             message = Resources.Load("Levels/General/generalSpeech3") as Texture;
             position = new Vector2(tabItem, Screen.height-avatarSize-2*tabItem-messageSize.y);
             displayMessage = true;    
         }
     }    
 }
 
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 asafsitner · Dec 26, 2012 at 06:39 PM 0
Share

Great to hear! You should accept your answer, then. :)

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

10 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

Related Questions

Starting and stopping Coroutines 1 Answer

Why is my Mathf.Lerp not lasting for the intended duration, even though I'm not using Time.time as the t variable? 1 Answer

how to change a value over time in a coroutine ? 2 Answers

Removing a GUITexture a set amount of time after it has been enabled. 1 Answer

Decrease the gravity in half for 10 seconds 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