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 BjarkeDuDe · Oct 11, 2012 at 02:51 PM · javascriptimagetimercountdown

Countdown/timer in Javascript

I'm basically trying to make an image fill up the whole screen, about 5 minutes after the game started, (in Javascript). I am a complete newbie to Javascript, so i have no idea how to do it. Help?

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

3 Replies

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

Answer by Noah-1 · Oct 11, 2012 at 05:12 PM

Its simple, try something like this:

 //timer vars
 var startTime;
 var timer1:int;
 var texture1: GUITexture;
 
 
 function Update(){TimerStart();}
 
 
 
 function TimerStart(){
 
 startTime = Time.time; //time starter
 
 timer1 = Time.time;  //Set time
 
 if(timer1 > 5){ //<-------the number here are the seconds you want
 
 Debug.Log ("Time is over, render texture now");
 
 //Here we just enable a GUI texture on the screen (create a GUItexture and disable it)
 
 texture1.enabled = true;
 
 
 }
 }

Basically you just wait for the time you want and then enable a texture that is already on the screen.

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 BjarkeDuDe · Oct 11, 2012 at 05:35 PM 0
Share

Thank you, that worked really well! :D

avatar image Noah-1 · Oct 11, 2012 at 05:40 PM 0
Share

I'm glad it helped.

avatar image
0

Answer by PulseLight · Oct 11, 2012 at 07:32 PM

5 minutes is 60*5 seconds so:


     if (Time.timeSinceLevelLoad >= 60*5)
     {
      //load the image here
     }
 
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 PulseLight · Oct 11, 2012 at 03:15 PM 0
Share

also if you want the counter to show on the screen you can use this:

function OnGUI() { GUI.Box(Rect(0,0,100,30),"Time = "+$$anonymous$$athf.FloorToInt(Time.timeSinceLevelLoad)); }

I'm converting the Time.timeSinceLevelLoad to Int using $$anonymous$$athf.FloorToInt so it won't show with decimals, just seconds.

avatar image mremus · Apr 04, 2013 at 02:27 PM 0
Share

Being new to scripting what would the display timer code look like to get the timer to appear in a standard $$anonymous$$ute and second time format 0:00 ?

avatar image
0

Answer by kmeboe · Oct 11, 2012 at 03:50 PM

You can delay the call of a method for a certain amount of time by using Invoke: http://answers.unity3d.com/questions/24799/time-function-in-javascript.html

To display an image, use GUI.DrawTexture: http://docs.unity3d.com/Documentation/ScriptReference/GUI.DrawTexture.html

Good luck!

Comment
Add comment · Show 3 · 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 BjarkeDuDe · Oct 11, 2012 at 04:58 PM 0
Share

Thank you very much! xD

avatar image kmeboe · Oct 11, 2012 at 05:03 PM 0
Share

You're welcome! Don't forget to mark the question as answered.

avatar image Mattolio · Feb 27, 2014 at 09:50 PM 0
Share

How would one reset the timer to start counting up again once it had reached it target?

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

15 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

Related Questions

Mini Game Timer - Unity 2017 0 Answers

How to make a simple battery? 0 Answers

Countdown 2 Answers

How to Display Map 1 Answer

Counting down in seconds opposed to frames 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