UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"open door by pressing key in game"
public class OpenTheDoor : MonoBehaviour { public GameObject TextDisplay; public float theDistance = PlayerCasting.DistanceFromTarget; public GameObject theDoor; void Update() { theDistance = PlayerCasting.DistanceFromTarget; if (Input.GetButtonDown("Action")) { if(theDistance <= 2) { StartCoroutine(OpenTheDoor()); } } } private void OnMouseOver() { if(theDistance <= 2) { TextDisplay.GetComponent<Text>().text = "Press E To Open The Door"; } } private void OnMouseExit() { TextDisplay.GetComponent<Text>().text = ""; } IEnumerator OpenTheDoor() { theDoor.GetComponent<Animation>().Play("Door1"); yield return new WaitForSeconds(5); theDoor.GetComponent<Animation>().Play("Door2"); } }