- Home /
Problem with time !! help me
When my car collide with an object maxspeed change to 180 but i need that stop after 5 seconde and maxspeed back by defaut 150 ... there is my script it dosen't work :
var intervalTimer = 0.0 ;
var interval = 0.0 ;
var maxspeed : float = 150 ;
function Start () {
intervalTimer=Time.time;
interval=5 ; }
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag=="other"){
var newtime = intervalTimer+interval ;
if (newtime>Time.time){
maxspeed=200 ;
}
else if(newtime<=Time.time) {maxspeed=150 ;
}
}
}
Comment
Answer by KiraSensei · Feb 26, 2014 at 09:24 AM
You don't initialise intervalTimer at the right place :
var interval : float = 0.0;
var maxspeed : float = 150;
private var newtime : float =0.0f;
function Start () {
interval=5;
}
function OnCollisionEnter (collision : Collision) {
if(collision.gameObject.tag=="other")
{
newtime = Time.time+interval ;
}
}
function Update () {
if (newtime>Time.time){
maxspeed=200 ;
}
else maxspeed=150 ;
}