#pragma strict
import UnityEngine.UI;
var startingHealth : int = 100;
var currentHealth : int;
var healthSlider : Slider;
var damageImage : Image;
var deathClip : AudioClip;
var flashSpeed : float= 5f;
var flashColour : Color = new Color(1f, 0f, 0f, 0.1f);
private var isDead : boolean;
private var damaged : boolean;
private var chMotor : CharacterMotor;
private var foot : footstepbyjeevan;
var DeathClip: AudioClip;
var HurtClip : AudioClip;
var damageTexture : Texture;
var HurtTexture : Texture;
var cleanTexture :Texture;
function Awake ()
{
chMotor=GetComponent(CharacterMotor);
foot=GetComponent(footstepbyjeevan);
currentHealth = startingHealth;
}
function Update ()
{
if(damaged)
{
damageImage.color = flashColour;
damaged=true;
}
if(damaged==true)
{
damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
}
damaged = false;
}
public function TakeDamage (amount : int)
{
damaged = true;
currentHealth -= amount;
healthSlider.value = currentHealth;
GetComponent.<AudioSource>().clip =HurtClip[Random.Range(0,HurtClip.Length)];
GetComponent.<AudioSource>().Play();
if(currentHealth <= 0 && !isDead)
{
Death ();
}
}
function Death ()
{
isDead = true;
GetComponent.().Play(“Death”, PlayMode.StopAll);
chMotor.enabled=false;
foot.enabled = false;
GetComponent.<AudioSource>().clip =DeathClip[Random.Range(0,DeathClip.Length)];
GetComponent.<AudioSource>().Play();
}
function OnGUI ()
{
if(damaged)
{
GUI.color = Color(1.0, 1.0, 1.0); //Color (r,g,b,a)
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), HurtTexture);
}
else
{
damaged=false;
GUI.color = Color(1.0, 1.0, 1.0); //Color (r,g,b,a)
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height),cleanTexture );
}
if(currentHealth <= 0)
{
GUI.color = Color(1.0, 1.0, 1.0); //Color (r,g,b,a)
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height),damageTexture );
}
}