Refactor player and enemy scripts; remove unused classes and improve initialization
- Added base initialization call in PlayerController. - Changed player reference in EnemyAI to be serialized for better inspector visibility. - Ensured characters are initialized upon spawning in EnemySpawner. - Removed obsolete EnemyAI and Chest scripts to streamline codebase. - Added KeyChest script for key collection functionality. - Introduced new meta files for better organization and tracking. - Created launch configuration for Unity debugging.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class KeyChest : MonoBehaviour
|
||||
{
|
||||
private bool _isOpened = false;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
if (_isOpened)
|
||||
return;
|
||||
|
||||
var playerState = collider.GetComponent<PlayerState>();
|
||||
if (playerState != null)
|
||||
{
|
||||
_isOpened = true;
|
||||
|
||||
// Update player state
|
||||
playerState.SetKey();
|
||||
|
||||
// Notify GameManager of key collection
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.SetKeyState(true);
|
||||
}
|
||||
|
||||
// Notify LevelManager of key collection
|
||||
if (LevelManager.Instance != null)
|
||||
{
|
||||
LevelManager.Instance.NotifyKeyCollected();
|
||||
}
|
||||
|
||||
// Destroy the chest
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user