fgm24/Assets/Scripts/Player/PlayerHP.cs

38 lines
819 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class PlayerHP : MonoBehaviour
{
public int maxHealth = 100;
public int currentHealth;
public TextMeshProUGUI healthText;
void Start()
{
currentHealth = maxHealth;
}
public void Update()
{
if (currentHealth <= 0)
{
// TODO: Game Over
}
if (healthText != null && currentHealth > 0)
{
healthText.text = "Health: " + currentHealth;
}
else if (healthText != null && currentHealth <= 0)
healthText.text = "Health: 0";
if (Input.GetKeyDown(KeyCode.Space))
TakeDamage(5);
}
public void TakeDamage(float damage)
{
currentHealth -= (int)damage;
}
}