I need to understand how can I do to active some trigger when I look this trigger.
I have created this script:
using UnityEngine;
using System.Collections;
public class Rotating_Normal_Door : MonoBehaviour {
public bool open = false;
public bool interaction = false;
public bool locked = false;
private Animator anim;
private int openDoor = Animator.StringToHash("Open");
void Start () {
anim = GetComponent<Animator> ();
}
void Update () {
if (Input.GetKeyDown ("e") && interaction == true && locked == false) {
changeDoorState ();
}
}
void OnTriggerEnter (Collider col) {
if (col.gameObject.tag == "Player")
{
interaction = !interaction;
}
}
void OnTriggerExit (Collider col) {
if (col.gameObject.tag == "Player")
{
interaction = !interaction;
}
}
void changeDoorState () {
if (open == false) {
anim.SetBool (openDoor, true);
open = true;
}
else {
anim.SetBool (openDoor, false);
open = false;
}
}
}
When I enter into the trigger I will be able to press E to open the door, but I want add the condition that I will be able to press E only when I look the trigger.
How can i do that? Please help!