Hi,
We’ll I thought it would be simple.
I’m trying to get this blood fade script to work but getting a little confused.
What I’m doing is calling the damage function from the enemy scripts, so when the enemy is shooting the player the blood fades in, then when they are not the update function fades the blood back out, I did have a global variable controlling the fade out in the update function set to false when the enemy ray cast was hitting the player but when two or more enemy was in the scene it was always set to false if one of them was not attacking the player, so I want it all to be set in this script.
So I’m trying to hold back the fade out while the damage function is being called but getting confused how the best way of doing this would be.
#pragma strict
var bloodSplatter : Texture2D;
private var fade : float;
private var gapSet : boolean;
function Update(){
// If the Player is NOT taking damage slowly fade out the blood effect
if(!gapSet && fade > 0){
fade = fade - 0.02;
GapSetBloodSplatter();
}
}
// Function called from enemy scrips
function damage(healthToDeduct : float){
// If the Player IS taking damage slowly fade in the blood effect
if(fade < 1){
fade = fade + healthToDeduct / 100;
}
}
function GapSetBloodSplatter(){
gapSet = true;
yield WaitForSeconds (0.05);
gapSet = false;
}
function OnGUI(){
GUI.color.a = fade;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), bloodSplatter);
}