working on health and passing turn without using two dice pairs
This commit is contained in:
parent
31917ba415
commit
63209a12dc
5 changed files with 245 additions and 0 deletions
23
PuzzleGameProject/Assets/Scripts/PassManager.cs
Normal file
23
PuzzleGameProject/Assets/Scripts/PassManager.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Video;
|
||||
using Button = UnityEngine.UI.Button;
|
||||
|
||||
public class PassManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button passButton;
|
||||
|
||||
public event EventHandler PassRequested;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
passButton.onClick.AddListener(OnPassClicked);
|
||||
}
|
||||
|
||||
private void OnPassClicked()
|
||||
{
|
||||
PassRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
2
PuzzleGameProject/Assets/Scripts/PassManager.cs.meta
Normal file
2
PuzzleGameProject/Assets/Scripts/PassManager.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95487118287b4514fb9b9fb7018ae717
|
||||
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();
|
||||
}
|
||||
}
|
||||
2
PuzzleGameProject/Assets/Scripts/Player.cs.meta
Normal file
2
PuzzleGameProject/Assets/Scripts/Player.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 516f63f4d32b3614b92fb0535c742078
|
||||
Loading…
Add table
Add a link
Reference in a new issue