void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Item") // entra en contacto con un iterm y se activa la capacidad de interactuar con este { PickableItem pim = other.GetComponent <PickableItem>(); currentItem = pim; canInteract = true; } else if (other.tag == "RoomDetector") { if (other.gameObject.GetComponent <PickableItem>() != null) { //La puerta tiene un candado currentItem = other.GetComponent <PickableItem>(); canInteract = true; } else if (other.GetComponent <RoomDetectorContoller>() != null) { currentRoomDetector = other.GetComponent <RoomDetectorContoller>(); canGoDoor = true; } else if (other.GetComponent <DoorwayLockController>() != null) { doorwayLockDetector = other.GetComponent <DoorwayLockController>(); canInteract = true; } } }
void OnTriggerExit2D(Collider2D other) { if (other.tag == "Item") { PickableItem pim = other.GetComponent <PickableItem>(); if (currentItem != null && pim == currentItem) { currentItem = null; canInteract = false; } } else if (other.tag == "RoomDetector") { if (other.gameObject.GetComponent <PickableItem>() != null) { PickableItem pim = other.GetComponent <PickableItem>(); if (currentItem != null && pim == currentItem) { currentItem = null; canInteract = false; } } else if (other.gameObject.GetComponent <RoomDetectorContoller>() != null) { currentRoomDetector = null; canGoDoor = false; } else if (other.gameObject.GetComponent <DoorwayLockController>() != null) { doorwayLockDetector = null; canInteract = false; } } }