fgm24/Assets/Scripts/Player/PlayerHP.cs

38 lines
819 B
C#
Raw Normal View History

2024-02-02 20:05:03 +01:00
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)
2024-02-02 20:26:17 +01:00
healthText.text = "Health: 0";
if (Input.GetKeyDown(KeyCode.Space))
TakeDamage(5);
2024-02-02 20:05:03 +01:00
}
public void TakeDamage(float damage)
{
currentHealth -= (int)damage;
}
}