Implemented torch ability
This commit is contained in:
parent
0bf8adc76d
commit
9a8077021a
15 changed files with 881 additions and 49 deletions
58
PuzzleGameProject/Assets/Scripts/Abilities/TorchAbility.cs
Normal file
58
PuzzleGameProject/Assets/Scripts/Abilities/TorchAbility.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TorchAbility : MonoBehaviour
|
||||
{
|
||||
public static
|
||||
event Action TorchAbilityUsed;
|
||||
[SerializeField] private GameObject abilityUseOne;
|
||||
[SerializeField] private GameObject abilityUseTwo;
|
||||
|
||||
private int _uses = 2;
|
||||
private GameObject[] _usesUsed;
|
||||
private bool _canClick;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
GameManager.StateChanged += HandleStateChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GameManager.StateChanged -= HandleStateChanged;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_usesUsed = new GameObject[_uses];
|
||||
abilityUseOne.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseOne));
|
||||
abilityUseTwo.GetComponent<Button>().onClick.AddListener(() => UseClicked(abilityUseTwo));
|
||||
}
|
||||
|
||||
private void UseClicked(GameObject abilityUseObject)
|
||||
{
|
||||
if (!_canClick) return;
|
||||
|
||||
if (_uses > 0)
|
||||
{
|
||||
_usesUsed[_uses - 1] = abilityUseObject;
|
||||
MarkUsed(abilityUseObject);
|
||||
TorchAbilityUsed?.Invoke();
|
||||
_uses -= 1;
|
||||
}
|
||||
|
||||
_canClick = false;
|
||||
}
|
||||
|
||||
private void MarkUsed(GameObject useObject)
|
||||
{
|
||||
useObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
|
||||
}
|
||||
|
||||
private void HandleStateChanged(GameState state)
|
||||
{
|
||||
_canClick = true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue