Created
October 2, 2015 10:10
-
-
Save DB-009/01b78aaf4fcac116e028 to your computer and use it in GitHub Desktop.
3 Timers in one script, for unity c#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using System; | |
| public class Timers : MonoBehaviour { | |
| public float myTimer;//First timer variable | |
| public float myCountdown= 10f; //Second timer (countdown) variable | |
| public float myStartTime;//Third timer start time | |
| public float myCurTime;//Third timer Current time | |
| // Use this for initialization | |
| void Start () | |
| { | |
| myStartTime = Time.time; | |
| } | |
| // Update is called per frame | |
| void Update () | |
| { | |
| myTimer += Time.deltaTime;//my first timer | |
| myCountdown -= Time.deltaTime;//my second timer | |
| myCurTime = Time.time - myStartTime;//my third timer | |
| //actions performing when certain times are reached | |
| if( myTimer >= 5) | |
| { | |
| transform.Translate(2 * Time.deltaTime ,0,0); | |
| } | |
| if (myCountdown <= 0) | |
| { | |
| Debug.Log("My message"); | |
| myCountdown = 10f; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment