using UnityEngine; public class KeyChest : MonoBehaviour { private bool _isOpened = false; private void OnTriggerEnter2D(Collider2D collider) { if (_isOpened) return; var playerState = collider.GetComponent(); 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); } } }