// Update is called once per frame void Update() { if (IsLocked) { bool hasPressedF = false; if (Input.GetButtonDown("Use")) { hasPressedF = true; } if (player.IsLookingAt(this.gameObject)) { lostSight = false; inSight = true; if (playerKeyController.HasKey()) { textToDisplay.text = "Appuyer sur F ou L1 pour ouvrir"; if (hasPressedF) { textToDisplay.text = ""; animatorController.SetTrigger("open"); playerKeyController.UseKey(); switch (type) { //If it's a chest => drop treasure case Type.CHEST: treasure.DropTreasure(); IsLocked = false; break; //If it's a door => delete collider case Type.DOOR: ItemSoundManager.Instance.DoorSound(); GetComponent <Collider2D>().enabled = false; IsLocked = false; break; } } } else { textToDisplay.text = "Il vous faut une clé pour ouvrir"; } } else { if (inSight) { inSight = false; lostSight = true; } } } if (lostSight) { textToDisplay.text = ""; } }