Implemented turn passing and taking damage from it.
This commit is contained in:
parent
31917ba415
commit
ede5ef1533
6 changed files with 572 additions and 15 deletions
39
PuzzleGameProject/Assets/Scripts/Player.cs
Normal file
39
PuzzleGameProject/Assets/Scripts/Player.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using Microsoft.Unity.VisualStudio.Editor;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int maxHealth;
|
||||
[SerializeField] private GameObject healthGameObject;
|
||||
private int _healthIndex = 0;
|
||||
private readonly int[] _healthBar = {0, 0, -1, -2, -4, -6, -9, -12, -16, -20};
|
||||
|
||||
private void Start() {
|
||||
UpdateGUI();
|
||||
}
|
||||
|
||||
public void TakeDamage(int damage)
|
||||
{
|
||||
if (_healthIndex + damage < _healthBar.Length)
|
||||
{
|
||||
_healthIndex += damage;
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int healAmount)
|
||||
{
|
||||
if (_healthIndex - healAmount >= 0)
|
||||
{
|
||||
_healthIndex -= healAmount;
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGUI()
|
||||
{
|
||||
healthGameObject.GetComponent<TextMeshProUGUI>().text = _healthBar[_healthIndex].ToString();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue