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 DarksDaemon · Feb 20, 2013 at 03:08 AM · guiyieldcountdown

3, 2, 1 GO!

So I'm trying to get a 3, 2, 1 GO! thing going on but It just doesn't seem to be working, no errors just not working, any help?

     private bool showCountdown;
     private string countdown = "";
     
     void Start () {
         instance = this;
         GameEventManager.GameStart += GameStart;
         GameEventManager.GameOver += GameOver;
         gameOverText.enabled = false;
     }
 
     void Update () {
         if(Input.GetButtonDown("Jump")){
             GetReady();
             GameEventManager.TriggerGameStart();
         }
         if (Input.touchCount > 0){
             GameEventManager.TriggerGameStart();
         }
     }
     
     IEnumerator GetReady () {
         showCountdown = true;
             
         countdown = "3";
         yield return new WaitForSeconds (1.5f);
         
         countdown = "2";
         yield return new WaitForSeconds (1.5f);
         
         countdown = "1";
         yield return new WaitForSeconds (1.5f);
             
         countdown = "GO!";
         yield return new WaitForSeconds (1.5f);
         
 
         showCountdown = false;
         countdown = "";    
                     
     }
     
     void OnGUI(){
         if (showCountdown){    
                GUI.color = Color.red;    
                GUI.Box (new Rect (Screen.width / 2 - 100, Screen.width / 2, 200, 175), "GET READY");
                 
                GUI.color = Color.white; 
                GUI.Box (new Rect (Screen.width / 2 - 90, Screen.width / 2, 180, 140), countdown);
         }    
     }
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
1
Best Answer

Answer by falconer · Feb 20, 2013 at 07:53 PM

you could use this code instead,

 var guiCountDown : GUIText;
 var countMax : int;
 private var countDown : int;
 
 function Start(){
 
     guiCountDown.enabled=true;
     GameStart();
 }
 
 function Update () {
 }
 
 function GameStart(){
     var car = gameObject.Find("NAME_OF_CAR");
     var drivingScript = car.GetComponent("NAME_OF_DRIVING_SCRIPT");
     drivingScript.enabled=false;
     
     
     
     for (countDown = countMax; countDown>0;countDown--){
         guiCountDown.text = countDown.ToString();
         yield WaitForSeconds(1);
     }
     
     guiCountDown.enabled=false;
     drivingScript.enabled=true;
     
 }
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 falconer · Feb 20, 2013 at 07:56 PM 0
Share

create a GUIText and add it to the script in the inspector section.make sure it is positioned so that it can be seen on the screen where the car runs. Set countdownmax to 3 if you want the count to start from 3..

avatar image DarksDaemon · Feb 20, 2013 at 08:09 PM 0
Share

completely rewrote my code using a guitext object, looks nothing at all like this code but the part about guitext helped me realize how to fix it

avatar image falconer · Feb 20, 2013 at 08:11 PM 0
Share

Glad you could fix it! Happy Coding :)

avatar image
1

Answer by robertbu · Feb 20, 2013 at 04:46 AM

To run a coroutine you need to call StartCoroutine() rather than call the routine directly. For example:

 StartCoroutine(GetReady());
Comment
Add comment · Show 5 · 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 DarksDaemon · Feb 20, 2013 at 07:36 PM 0
Share

O$$anonymous$$ I've changed that but it's still not working, it kinda just skips the countdown and starts the game.

avatar image falconer · Feb 20, 2013 at 07:40 PM 0
Share

Have you added the script to the car?

avatar image DarksDaemon · Feb 20, 2013 at 07:44 PM 0
Share

Well it's not on the runner it's on a gameobject that handles the GUI and general stuff.

avatar image falconer · Feb 20, 2013 at 07:45 PM 0
Share

ok, I think you should disable the driving script until the countdown is completed.

avatar image DarksDaemon · Feb 20, 2013 at 07:47 PM 0
Share

The 'driving' script IS disabled until the game 'starts', the problem is the countdown isn't even happening at all.

avatar image
0

Answer by Gabriel Quijada · Feb 23, 2013 at 01:00 AM

In fact you have to call the coroutine whit

 StartCoroutine("GetReady"); 

that should works

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 Bunny83 · Feb 23, 2013 at 01:04 AM 0
Share

Uhm, it's better to call it like robertbu said. It's faster, less error prone and allows more than one parameters.

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

12 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

Related Questions

Coin Counting Problem 0 Answers

Countdown To Start Game 2 Answers

Countdown remove gui.box 2 Answers

Why is yield not working for me? 2 Answers

Problems in c# countdown timer 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