using UnityEngine; public class PlayerInventory : MonoBehaviour { public bool hasKey = false; public KeyUi keyUi; // Drag your UI controller here in Inspector public void CollectKey() { if (!hasKey) { hasKey = true; Debug.Log("Key collected!"); if (keyUi != null) { keyUi.SetKeyCollected(true); // Update UI } } } void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Key")) { CollectKey(); Destroy(other.gameObject); // Remove key from scene } } }