39e4e51866
- Implemented PlayerController.cs to manage player movement and actions. - Created PlayerState.cs to track player lives, coins, and key status. - Added CameraFollow.cs for smooth camera movement following the player. - Developed Character.cs as an abstract class for character behavior. - Introduced Enums.cs for defining TreasureType and MapElementType. - Added IDoor interface for door interactions. - Created InputActions.cs for handling player input actions. - Implemented MainMenu.cs for basic menu functionality including play and exit options.
45 lines
958 B
C#
45 lines
958 B
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private TextMeshProUGUI _totalCoins;
|
|
[SerializeField]
|
|
private GameObject _keyIcon;
|
|
|
|
private PlayerState _playerState;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
_playerState = GetComponent<PlayerState>();
|
|
if (_playerState != null)
|
|
{
|
|
_playerState.OnPlayerTakeItem += UpdateUi;
|
|
}
|
|
}
|
|
|
|
private void UpdateUi(object sender, TreasureType e)
|
|
{
|
|
switch (e)
|
|
{
|
|
case TreasureType.Coin:
|
|
_totalCoins.text = _playerState.TotalCoins.ToString();
|
|
break;
|
|
case TreasureType.Key:
|
|
_keyIcon.SetActive(true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (_playerState != null)
|
|
{
|
|
_playerState.OnPlayerTakeItem -= UpdateUi;
|
|
}
|
|
}
|
|
}
|
|
|