Working on health and passing turn without using two dice pairs
This commit is contained in:
parent
31917ba415
commit
9e6cbb22da
5 changed files with 521 additions and 4 deletions
33
PuzzleGameProject/Assets/Scripts/Player.cs
Normal file
33
PuzzleGameProject/Assets/Scripts/Player.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Microsoft.Unity.VisualStudio.Editor;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int health;
|
||||
[SerializeField] private int maxHealth;
|
||||
[SerializeField] private GameObject healthGameObject;
|
||||
|
||||
public void TakeDamage(int damage)
|
||||
{
|
||||
if (health + damage > 0)
|
||||
{
|
||||
health -= damage;
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int healAmount)
|
||||
{
|
||||
if (health + healAmount <= maxHealth)
|
||||
{
|
||||
health += healAmount;
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGUI()
|
||||
{
|
||||
healthGameObject.GetComponent<TextMeshProUGUI>().text = health.ToString();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue