Skip to content

Instantly share code, notes, and snippets.

@DB-009
Created October 2, 2015 10:10
Show Gist options
  • Select an option

  • Save DB-009/01b78aaf4fcac116e028 to your computer and use it in GitHub Desktop.

Select an option

Save DB-009/01b78aaf4fcac116e028 to your computer and use it in GitHub Desktop.
3 Timers in one script, for unity c#
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