Refactor and reorganize scripts for improved structure and functionality
- Removed obsolete scripts: Chest, BreakableWall, Door, DoorInteract, and UiManager. - Moved Chest and BreakableWall scripts to EnvironmentObjects folder. - Introduced HammerThrower class to manage hammer throwing mechanics. - Updated PlayerController to utilize new InputManager and HammerThrower. - Refactored PlayerState to manage player state and item collection. - Enhanced UI management in UiManager to reflect player item collection. - Updated EnemyAI to remove unused movement logic. - Adjusted KeyChest to interact with PlayerState instead of Player. - Cleaned up code and improved event handling for item collection.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user