RenatoB, I tested your script and it really runs fast like a crazy horse! The problem is the type of the currlife var: if you don’t specify the type, javascript will do it for you, right or wrong! That’s a golden rule in unity’s javascript: always define the type of any var. When javascript finds an untyped variable, it must decide at runtime which’s the type of its contents; it wastes CPU time and may generate errors. I fixed your script and there it goes:
var bar: boolean;
var maxlife: float = 100;
var currlife: float = 100;
function Start(){
bar = false;
}
function Update(){
if (bar == false){
currlife = 100;
} else {
currlife -= 1.0 * Time.deltaTime;
}
}
function OnTriggerEnter(){
bar = true;
}
function OnTriggerExit(){
bar = false;
}