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 Kingsamuraix · Aug 24, 2012 at 07:25 PM · timergame over

Game over?

I have a timer and and when the time runs out I want a button to appear that says time is up, game over, and play again. Im not sure how to do this or where to put it. heres what i have for my code.

[code]

 var isPaused:boolean = false;
 var startTime:float;
 var timeRemaining:float;
 var percent:float;
 var clockBG:Texture2D;
 var clockFG:Texture2D;
 var clockFGMaxWidth:float;
 
 
 function Start()
 {
 guiText.material.color  = Color.black;
 startTime = 10;
 clockFGMaxWidth = clockFG.width;
 }
 
 function Update () {
 if(!isPaused)
 {
 DoCountdown();
 }
 }
 
 function DoCountdown()
 {
 timeRemaining = startTime - Time.timeSinceLevelLoad;
 percent = timeRemaining/startTime * 100;
 if (timeRemaining <0)
 {
 timeRemaining = 0;
 isPaused = true;
 TimeIsUp();
 }
 Showtime();
 Debug.Log(" time remaining = " + timeRemaining);
 }
 
 function PauseClock()
 {
 isPaused =  true;
 }
 
 function UnPauseClock()
 {
 isPaused = false;
 }
 
 function Showtime()
 {
 var minutes:int;
 var seconds:int;
 var timeStr:String;
 minutes = timeRemaining/60;
 seconds = timeRemaining % 60;
 timeStr = minutes.ToString() + ":";
 timeStr += seconds.ToString("D2");
 guiText.text = timeStr;
 }
 
 function TimeIsUp()
 {
 Debug.Log("Time Is Up");
 }
 
 function OnGUI()
 {
 var newBarWidth:float = (percent/100) * clockFGMaxWidth;
 var gap:int = 20;
 var isPastHalfway:boolean = percent<50;
 var clockRect:Rect = Rect(0,0,128,128);
 var rot:float = (percent/100) * 360;
 var centerPoint:Vector2 = Vector2(64, 64);
 var startMatrix:Matrix4x4 = GUI.matrix;
 
 
 GUI.BeginGroup(new Rect (Screen.width - clockBG.width -gap, gap, clockBG.width, clockBG.height));
 GUI.DrawTexture(Rect(0,0,clockBG.width, clockBG.height), clockBG);
 GUI.BeginGroup(new Rect(5,6,newBarWidth,clockFG.height));
 GUI.DrawTexture(Rect(0,0,clockFG.width, clockFG.height), clockFG);
 GUI.EndGroup();
 GUI.EndGroup();
 }

[/code]

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
0
Best Answer

Answer by Fattie · Aug 24, 2012 at 07:59 PM

are you familiar with the Invoke() command ? (there's also InvokeRepeating() )

it makes things like this incredibly easy. Check it out.

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 Kingsamuraix · Aug 24, 2012 at 08:51 PM 0
Share

Thanks, that helped me out

avatar image Fattie · Aug 24, 2012 at 09:03 PM 0
Share

No problem. It's really strange, it is the most common command you use everyday to make video games. But very many programmers new to Unity have never heard of it. it's just one of those things! Cheers

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No esc when game over. 1 Answer

Display Time At Game Over Scene 1 Answer

Script for Car 2 Answers

Game over when time reached 1 Answer

Start timer with Input 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