using UnityEngine; using UnityEngine.Experimental.Rendering.Universal; public class Key : Item { public int connectedDoorID; private AudioSource aSource; private Light2D itemLight; private bool pickedUp; private void Start() { aSource = GetComponent<AudioSource>(); itemLight = GetComponent<Light2D>(); } private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Player")) { collision.gameObject.GetComponent<ItemInventory>().PickUpKey(this); aSource.Play(); pickedUp = true; GetComponent<BoxCollider2D>().enabled = false; } } private void Update() { if (pickedUp) { if (GetComponent<SpriteRenderer>().enabled) GetComponent<SpriteRenderer>().enabled = false; itemLight.enabled = false; if (!aSource.isPlaying) gameObject.SetActive(false); } } public int GetKeyID() { return connectedDoorID; } }