ad6388f330
- 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.
38 lines
867 B
C#
38 lines
867 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
|