- Home /
damage cooldown
how to do a damage cooldown just like when you have a gun and there is an interval on every shot
Answer by Lockstep · Feb 01, 2013 at 04:48 PM
Just define a boolean to check if you want to recieve damage. Maybe like this example written in C#:
Inside of your monobehaviour:
public float invulTime = 1f // The time you stay invulnerable after a hit
public float health = 100; // The players health obviously
private bool invulnerable = false; // this boolean gets checked inside of the Damage function.
public void ApplyDamage(float dmg){
if(!invulnerable){
health -= dmg;
StartCoroutine(JustHurt());
}
}
IEnumerator JustHurt(){
invulnerable = true;
yield return new WaitForSeconds(invulTime);
invulnerable = false;
}
public someType someVariable= something;
becomes
var someVariable : someType = something;
that applies for every variable(bool becomes boolean thought). Js will also recognize the type on its own so you can leave out the declaration. I.e. if you type
var invultime = 1.0;
Js will know that invultime is a float. Same goes for functions:
public void SomeFunction ()
becomes
function SomeFunction() : void
again this applies for any function. You also don't need to declare the return type for the function (in this case nothing noted by the word "void"). And it will know if it's a regular function or a coroutine (Ienumerator) on its own. Finally ins$$anonymous$$d of
yield return new WaitForSeconds(someFloat);
you can simply use
yield WairForSeconds(someFloat);
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
C# How to have a gun select 1 Answer
having trouble with ammo reload script. destorys extra ammo 1 Answer
Help with gun scripting!? 1 Answer
Gun swap through collision 1 Answer