ReisenYoumuOuting/Assets/Scripts/Entities/Player.cs

61 lines
1.6 KiB
C#

using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Player : Entity
{
[Header("Invulnerability")]
[SerializeField] private float invulnerabilityLength;
private float currentInvulnerabilityTime;
[Header("UI")]
[SerializeField] private TextMeshProUGUI livesText;
[Header("SFX")]
[SerializeField] private AudioClip hurtSound;
[SerializeField] private float hurtVolume = 1f;
private void Update()
{
if (!isStalled)
{
if (Input.GetMouseButtonDown(0))
{
abilities[0].TryAbility();
}
if (Input.GetMouseButtonDown(1)) //this way kinda sucks but i'll fix it when i feel like it
{
abilities[1].TryAbility();
}
}
if (currentInvulnerabilityTime > 0)
{
currentInvulnerabilityTime -= Time.deltaTime;
if (currentInvulnerabilityTime <= 0)
{
invulnerable = false;
}
}
}
public override void TakeDamage(int damage)
{
base.TakeDamage(damage);
if (!invulnerable)
{
WaveManager.instance.audioSource.PlayOneShot(hurtSound, hurtVolume);
currentInvulnerabilityTime = invulnerabilityLength;
invulnerable = true;
}
UpdateLivesUI();
GameManager.instance.livesLost++;
}
protected override void OnDeath()
{
GameManager.instance.LoseGame();
}
private void UpdateLivesUI()
{
livesText.text = $"Lives: {health}/{maxHealth}";
}
}