/// <summary>
/// PlayerEnergy handles the energylevel of the player.
/// </summary>
public class PlayerEnergy : CharResource
{
public Transform cameraObject;
private Transform myTransform;
private bool godMode = false;
private bool lastHit = false;
private AudioManager audioManager;
/// <summary>
/// Start this instance.
/// </summary>
private void Start ()
{
alive = true;
myTransform = transform;
audioManager = myTransform.GetComponent<AudioManager>();
screenOverlay = cameraObject.GetComponent<ScreenOverlay>();
}
/// <summary>
/// Update this instance.
/// </summary>
private void Update ()
{
//AddjustResource(0);
RecieveFallDamage();
if(curValue <= 0 && lastHit)
{
Die();
}
}
/// <summary>
/// Processes the incoming damage.
/// </summary>
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");
}
/// <summary>
/// Is the energy depleted.
/// </summary>
/// <returns>
/// The Depleted Energy
/// </returns>
public bool EnergyDepleted()
{
if(CurValue <= 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Let this character die.
/// </summary>
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<BaseInputs>());
Destroy(GetComponent<PlayerMovement>());
GameObject gameMaster = GameObject.FindGameObjectWithTag("GameMaster");
Destroy(gameMaster.GetComponent<Pause>());
//Game over after 2 seconds
AutoFade.LoadLevel(Application.loadedLevel, 2, 1, Color.black);
alive = false;
}
}
}