///
/// PlayerEnergy handles the energylevel of the player.
///
public class PlayerEnergy : CharResource
{
public Transform cameraObject;
private Transform myTransform;
private bool godMode = false;
private bool lastHit = false;
private AudioManager audioManager;
///
/// Start this instance.
///
private void Start ()
{
alive = true;
myTransform = transform;
audioManager = myTransform.GetComponent();
screenOverlay = cameraObject.GetComponent();
}
///
/// Update this instance.
///
private void Update ()
{
//AddjustResource(0);
RecieveFallDamage();
if(curValue <= 0 && lastHit)
{
Die();
}
}
///
/// Processes the incoming damage.
///
public override void ProcessDamage(float damage)
{
//Reduce the current energy value
AddjustResource(damage);
//Screen effects enable
EnableScreenEffect(true);
StartCoroutine(ScreenEffectTimer(screenEffectTime));
//Audio
audioManager.PlayAudio(false, 1, 40, 0, "Voices/Player (Jack)",
"PlayerGettingHit1", "PlayerGettingHit2", "PlayerGettingHit3");
}
///
/// Is the energy depleted.
///
///
/// The Depleted Energy
///
public bool EnergyDepleted()
{
if(CurValue <= 0)
{
return true;
}
else
{
return false;
}
}
///
/// Let this character die.
///
public override void Die()
{
curValue = 0;
lastHit = true;
//Topple the player over
Quaternion targetRotation = Quaternion.Euler(40, 0, -90);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
targetRotation, Time.deltaTime * 4.0f);
if(alive)
{
//Audio
//audioScript.PlayDying("Jack");
myTransform.tag = "Untagged";
Destroy(GetComponent());
Destroy(GetComponent());
GameObject gameMaster = GameObject.FindGameObjectWithTag("GameMaster");
Destroy(gameMaster.GetComponent());
//Game over after 2 seconds
AutoFade.LoadLevel(Application.loadedLevel, 2, 1, Color.black);
alive = false;
}
}
}