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 bhasker · Feb 22, 2012 at 03:52 PM · timer

how to make timer in the game

hi, how to make a timer in the racing game,(i mean 3,2,1. GO!) THANK YOU....

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
1

Answer by Dreamside · Feb 22, 2012 at 04:15 PM

 using UnityEngine;
 using System.Collections;
 
 public class Timer : MonoBehaviour
 {
     float currentTime = 0;
     int countValue = 3;
     bool gameStarted = false;
 
     
     void Start()
     {
         currentTime = Time.time;
     }
 
     void Update()
     {
         if (!gameStarted)
         {
             if (Time.time - currentTime >= 1)
             {
                 Debug.Log(countValue);
                 countValue--;
                 currentTime = Time.time;
             }
             if (countValue == -1)
             {
                 gameStarted = true;
                 StartGame();
             }
         }
     }
     void StartGame()
     {
         Debug.Log("Game is started");
     }
 
 
 }
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 bhasker · Feb 23, 2012 at 04:09 PM 0
Share

To which i should attach this script,i been tryed attaching to the player,empty game object and it is saying can't add script.

avatar image Dreamside · Feb 23, 2012 at 04:12 PM 0
Share

You should attach it any gameobject you want but you should name script as Timer.cs

avatar image bhasker · Feb 23, 2012 at 04:54 PM 0
Share

it attached but the game starting normally.

avatar image
0

Answer by James Tima · Feb 23, 2012 at 04:27 PM

U can use GUI Text go to Game Object --> Create Other --> GUI Text and apply this script

 var TextTop : GUIText;         // assign GUI Text 


function ShowText()

{

   TextTop.text = "3";
 yield WaitForSeconds(1);
 TextTop.text = "2";
 yield WaitForSeconds(1);
 TextTop.text = "1";
 yield WaitForSeconds(1);
 TextTop.text = "Go....";
 }
Comment
Add comment · Show 4 · 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 bhasker · Feb 23, 2012 at 04:58 PM 0
Share

am trying to assign GUI text in the text top.but it is not assigning please help.

avatar image Dreamside · Feb 23, 2012 at 06:05 PM 0
Share

here is the silly question : TextTop is declared public right?

avatar image bhasker · Feb 23, 2012 at 06:15 PM 0
Share

i was trying to attach as shown in the script but it is not assigning,am new to the unity i don't know much about it.

avatar image James Tima · Feb 24, 2012 at 06:01 AM 0
Share

go to GameObject --> CreateOther -->GUI Text then u saw a GUI Text on hierachy view and where u attach script there u saw TextTop u just drage GUITxt from Hierachy view to TextTop.

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

7 People are following this question.

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

Related Questions

Visual timer? Like CUT THE ROPE 2 Answers

How can I rotate a shooting-practice target 180 degrees with a timer in C#? 1 Answer

Each update runs my code 6 times per line. Is it a bug? 1 Answer

Help with regenerating ammo 2 Answers

Timer that stops at trigger 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