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 Weither · Sep 09, 2013 at 07:48 PM · timertimer-script

Changing texture after 3s,4s and 5s

Hi. How to write code that change texture after 3, 4 and 5s. I mean something like that:

Timer is counting time.

If time is 0:30 show texture on screen with text(tips in game). I've got 10 textures in folder Textures. The texture should be background of the tip. The Texture is fading after 3s. Then comes next tip with new texture and it fade after 4s. Next fade after 5s, etc. How to do it?

I tried something like:

 Timer currTimer;
 Texture2D background1;
 Texture2D background2;
 [...]
     
 and then
 curTimer = new Timer();
 curTimer.Enabled = true;
 curTimer.Interval = 100 //checking time after 0.1s
     
 and then
     
 void Start()
    {
    if (Timer == "30000")
    {
 void OnGUI()
    {
    GUI.DrawTexture(rect(200,150, 0,0), "background");
    GUI.Text("To run faster press Shift");
    }

But it doesn't work(errors). Any ideas?

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 zipa · Sep 09, 2013 at 08:59 PM

Hello. If you don't need an exact time period you can use usual Unity's Update void.It will have a little time's epsilon.

         float startTime;
         private Texture2D targetTexture;
         public string textureName = "background";
         public int CountOfTextures = 10;
         private int textureIndex = 0;
         public int period = 3;
         private Rect rect = new Rect(200, 150, 0, 0);      
         void Start()
         {
             LoadTexture();
             startTime = Time.time;
         }
     
         void Update()
         {
             if (startTime + period < Time.time)
             {
                 startTime = Time.time;
                 textureIndex++;
                 period++;
                 if (textureIndex == CountOfTextures - 1)
                 {
                     textureIndex = 0;
                     period = 3;
                 }
                 LoadTexture();
             }
         }
     
         private void LoadTexture()
         {
             targetTexture = Resources.Load(textureName + textureIndex) as Texture2D;
             rect.width = targetTexture.width;
             rect.height = targetTexture.height;
         }
     
         void OnGUI()
         {
             GUI.DrawTexture(rect, targetTexture);
             GUI.Label(rect, "To run faster press Shift");
         }

Or you can make an array of background textures and change index of element of the array at the needed time.

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

Answer by Weither · Sep 09, 2013 at 09:25 PM

Thanks.

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

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

16 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to I get the timer counter to restart when the player hits the ground and respawns? 2 Answers

How do I implement a timer into this script that will record the total time the player has played. 2 Answers

Timer Text doesn't show the time in the script. 1 Answer

How do I stop my timer when all of the "dummies" are destroyed? 2 Answers

Not sure what is wrong with my timer script. 1 Answer


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