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 UnityNub · Oct 02, 2011 at 04:38 AM · guibooleanactivegame over

Game Over Screen Problem

Hello, I'm new to Unity and need some help. What I'm hoping to happen is for a box to show up when the timer reaches 0. For some reason it just wont happen. Here is my script.

 var Timer : float = 60;
 static var Level1TargetAmounts = 5;
 static var gameOver : boolean = false;
 function OnGUI () 
 {
     
     GUI.Label (Rect (10, 30, 100, 20), Timer.ToString());
     GUI.Label (Rect (10, 50, 200, 20), "Amount Of Targets Left : " );
     GUI.Label (Rect (160, 50, 100, 20), Level1TargetAmounts.ToString());
     if(gameOver.active == true)
     {
         GUI.Box (Rect (0, 0, Screen.width, Screen.height),"");
     }
 }
 
 function Update()
 {
     Timer -= Time.deltaTime; 
     if (Timer <= 0)
     {    
           Timer = 0;
           gameOver = true;
     }
 }

Any suggestions?

Comment
Add comment · Show 3
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 Grady · Oct 02, 2011 at 04:56 AM 0
Share

so, do you want the timer to be set to 0 after 60 seconds? because there is an easier way to do it if that is what you are trying to get at!!!!!!

avatar image syclamoth · Oct 02, 2011 at 06:17 AM 0
Share

What, WaitForSeconds(60);? Unfortunately, doing it that way does not allow the player to see how long there is left in the game.

avatar image Grady · Oct 02, 2011 at 06:20 AM 0
Share

oh yeah, true that

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by syclamoth · Oct 02, 2011 at 05:51 AM

One line-

 if(gameOver.active == true)

isn't really a thing. You should be using just

 if(gameOver)
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 Grady · Oct 02, 2011 at 05:55 AM

I would have said do something like this:

 function OnGUI () 
 {
 
     if(Time.time >= 60){
 
     GUI.Label (Rect (10, 30, 100, 20), Timer.ToString());
     GUI.Label (Rect (10, 50, 200, 20), "Amount Of Targets Left : " );
     GUI.Label (Rect (160, 50, 100, 20), Level1TargetAmounts.ToString());
     
        GUI.Box (Rect (0, 0, Screen.width, Screen.height),"");
     }
 
 }

That would make your GUI function code run after 60 seconds (1 minute).

I hope this is what you wanted, if not, the comment back!

-Grady

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 syclamoth · Oct 02, 2011 at 06:16 AM 0
Share

Presumably, the 'timer.tostring' bit is talking about a countdown to said 60 seconds, so I'm pretty sure you'd want to see that before the $$anonymous$$ute is up. Besides, this method only works once, and assumes you want to get in to the game immediately- no room for a main menu or any such thing. Using Time.time like this can cause unexpected behaviour if you want to be able to reset your timers.

avatar image
0

Answer by lbalasubbaiahapps · Oct 02, 2011 at 08:15 AM

using UnityEngine; using System.Collections;

[ExecuteInEditMode] public class TimeCountTransition : MonoBehaviour { public GUIText timeShow; public int time; public Texture2D texture_bg; //after time over

 //-----------------initalization of audio-----------------------------------------------------------------------------------------------------
 
 public AudioClip   ac_ButtonSound;
 
 public AudioSource audioSource;
         
     
 public GUIStyle myStyle;
 
 void OnGUI()
     {
         GUI.Label(new Rect(420,50,100,50),"Time:",myStyle);
         timeShow.text = time.ToString();
         
         if(time==5)
         {
             GUI.Label(new Rect(100,100,450,50),"Your time will be closed with in five seconds",myStyle);
         
         }
         
         if(time==0)
         {
             
             GUI.DrawTexture(new Rect(0,0,600,450),texture_bg);   //background texture
             GUI.Label(new Rect(150,200,300,250),"Your time is over if you want to play again press Restart button",myStyle);
             if(GUI.Button(new Rect(200,300,100,50),"Restart"))
             {
                 audioSource.PlayOneShot(ac_ButtonSound);
                 Application.LoadLevel(Application.loadedLevel);
             }
             else if(GUI.Button(new Rect(350,300,100,50),"Quit"))
             {
                 audioSource.PlayOneShot(ac_ButtonSound);
                 Application.LoadLevel("Start");
             
             }
             
         }
         
     }
 
 void Start ()
 {
     time=60;    
     InvokeRepeating("Subtract", float.Epsilon, 1);
 }
 
 void Subtract()
 {
     if(time > 0)
     {
         --time; 
     }
 }
 
 
 
 IEnumerator WaitTimeForScreen()
 {
     yield return new WaitForSeconds(1);
 }

}

once tried this one.if you want to time increment you can use ++time it will time increment.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI.skin Does not persist on next loop through is this a bug? 0 Answers

Why is Unity registering my false boolean as true? 1 Answer

activating game objects with a tag 1 Answer

Help with OnGUI ... multiple boxes showing? 1 Answer

switching the active boolean 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