How can i reset the count down timer when my player collides with an object
This is my code in java script:
pragma strict
var timer : float = 10.0; var plusTime : float = 10.0;
var guiShow : boolean = false;
function Update() { timer -= Time.deltaTime;
if(timer <= 0)
{
Application.LoadLevel("juego");
timer = 0;
}
}
function OnGUI() { GUI.Box(Rect(300, 10, 50, 20), "" + timer.ToString("0"));
if(guiShow == true)
{
GUI.Box(Rect(65, 10, 50, 20), "+" + plusTime.ToString("0"));
ShowGUI();
}
}
function ShowGUI() { yield WaitForSeconds(2); guiShow = false; }
Comment
Answer by Wolfrik_Creations · Nov 29, 2015 at 02:07 AM
function OnCollisionEnter(col:Collision) {
timer=10.0;
}
thanks for the answer but i have a question this code Works in a 2d game???? Beacuse my game is 2d i try to use :
function OnCollisionEnter(col:Collision) { timer=10.0; }
but nothing happens
Answer by nano005 · May 11, 2016 at 01:43 PM
You are missing the "2D" that comes after the word "Enter" when using 2D stuff. So it becomes OnCollisionEnter2D