How do I not set a trigger to happen?
So, basically, I am creating a script that triggers a door animation when the Player enters the door's collision box. It all works fine until the Player leaves the collision box. At the moment, the door stays open even after the Player has left. What I would prefer is for the door to close once the Player leaves the collision box.
Here is what I have put together using different posts and tutorials to try and achieve my goal:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DoorScript : MonoBehaviour {
public GameObject Door;
private Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
anim.SetBool ("character_nearby", true);
}
}
void OnTriggerExit(Collider other)
{
if(other.tag == "Player")
{
anim.SetBool ("character_far", true);
}
}
// Update is called once per frame
void Update () {
if(anim.GetBool("character_nearby"))
{
anim.SetTrigger("character_nearby");
}
else
{
if(anim.GetBool("character_far"))
{
anim.SetTrigger("character_far");
}
}
} }
Comment