I've been struggling with this for all day long, I want to make a door to stay open when the player is inside the trigger zone, but I cannot make it happen...
Here is what I did:
- A basic animations and animator (Open, Close, Idle/Default)
- Default transitions between states (with and without "Exit Time")
A basic script to check if the player is inside the trigger:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class DoorScript : MonoBehaviour { Animator _animator; bool doorOpen; // Use this for initialization void Start () { doorOpen = false; _animator = GetComponent<Animator>(); } /* // Update is called once per frame void Update () { } */ void OnTriggerEnter(Collider other) { if (other.tag == "Player") { doorOpen = true; DoorController("isOpen"); } } void OnTriggerExit(Collider other) { if (other.tag == "Player") { doorOpen = false; DoorController("isClosed"); } } void DoorController(string trigger) { _animator.SetTrigger(trigger); } }
And my result is the same, the animation of the door repeats itself even when the player is in the trigger zone, I tumbled upon some other resources (here... here... here... here I tried to copy what this person did, but is the same... here... and here) about doors and triggers, and I still don't know how I am wrong or what am I doing wrong, I tried everything in those links
The door goes through all animations regardless the script, and the parameters, when I move my player inside the trigger zone loops between open and close animations no matter what
Could some one help me with this?
Thanks in advance
EDIT:
Here are some screenshots of my animator and updated code, for this update I followed this tutorial, just a little difference, I'm using a FPS Controller from the Unity standard assets
Updated code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class DoorScript : MonoBehaviour { Animator _animator; bool doorOpen; // Use this for initialization void Start () { doorOpen = false; _animator = GetComponent<Animator>(); } /* // Update is called once per frame void Update () { } */ void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { doorOpen = true; DoorController("isOpen"); } } void OnTriggerExit(Collider other) { //These lines were modified if (doorOpen) { doorOpen = false; DoorController("isClosed"); } } void DoorController(string trigger) { _animator.SetTrigger(trigger); } } 



canClosebool and set that to true when you leave the trigger. As long there is no exit on your collisioncanCloseshould always be false once you enter the trigger. \$\endgroup\$