- Home /
Question about Damage Delay
I have been trying to get this damage script to delay how quickly it will damage whatever it is coming in contact with. It works, but it delays the first time it's supposed to hit for seemingly no reason. Any way to fix this?
var damage = 10;
var enable = true; var damageDelay = 3;
function OnControllerColliderHit (hit : ControllerColliderHit) { if(enable == true) { hit.gameObject.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); enable = false;
yield WaitForSeconds (damageDelay);
enable = true;
}
}
as the name says WaitForSeconds it actually use the float example 5.0 so I dont know why you put Time.deltaTime that terms are for other things not for yield WaitForSeconds and also you dont need *6
Answer by e-bonneville · Feb 14, 2011 at 10:18 PM
var damage = 10;
var enable = true; var damageDelay = 3;
function OnControllerColliderHit (hit : ControllerColliderHit) { if(enable == true) { hit.gameObject.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); enable = false;
yield WaitForSeconds (damageDelay);
enable = true;
}
}
I'm new at this. This doesn't fix the initial damage delay but you're right about my original code being confusing.
There really shouldn't be a delay from what I can see unless your ApplyDamage function has a delay built in. Is that the case?
No it isn't. We think it was an issue with our previous build for some odd reason. In our new build the issue was gone. Thanks for the help!
Your answer