I have built a playerHealth script and I did when the player loses life, meshrenderer to blink every 1 second but when he receives damage do more than once because when he feels damage and boolean when is activated, I have made is activated and make multiple times instead of a. How can I do to flash as I want? See the code:
var curHealth : int = 70;
var maxHealth : int = 100;
var deadMode = false;
var curProtect = false;
static var damageCost = 10;
function Update () {
if(curHealth >= maxHealth) {
curHealth = maxHealth;
}
if(curHealth <= 0) {
curHealth = 0;
deadMode = true;
}
if(curHealth > 0) {
deadMode = false;
}
protectedMode();
}
function OnTriggerEnter( other : Collider) {
if(other.tag == "Enemy" && !curProtect) {
curProtect = true;
curHealth -= damageCost;
}
}
function protectedMode() {
if(curProtect) {
graphicsSkin = transform.Find("Graphics");
graphicsSkin.renderer.enabled = false;
yield WaitForSeconds(1);
graphicsSkin.renderer.enabled = true;
yield WaitForSeconds(1);
graphicsSkin.renderer.enabled = false;
yield WaitForSeconds(1);
graphicsSkin.renderer.enabled = true;
yield WaitForSeconds(1);
graphicsSkin.renderer.enabled = false;
yield WaitForSeconds(1);
graphicsSkin.renderer.enabled = true;
yield WaitForSeconds(1);
curProtect = false;
}
}