I solved the problem myself
Open Door Animation Problem
I've created a rotating door with these properties:
When I approach the door, I can press "E" to open the door: after that i pressed "E", the animation of opening of the door starts, so the door will be open. Now, if i want close the door i have to re-press "E" on the door, indeed after that i pressed "E", the animation of closing of the door starts, but this animation starts with some seconds of delay. This is a problem because i want that animation starts right after that i pressed "E", without delay.
The script is this:
using UnityEngine;
using System.Collections;
public class Rotating_Normal_Door : MonoBehaviour {
public bool open = false;
public bool interaction = false;
public bool locked = false;
private Ray ray;
private Animator anim;
private int openDoor = Animator.StringToHash("Open");
void Start ()
{
anim = GetComponent<Animator> ();
}
void Update ()
{
RaycastHit hit;
ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
if (Input.GetKeyDown ("e") && interaction == true && locked == false && Physics.Raycast (ray, out hit))
{
if(hit.transform.name == name)
{
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;
}
}
}
Somebody can explain me where am i wrong?
I noticed that the delay time of the closing door animation it's variable, it is about 1 second, but sometimes it's less and sometimes it's more.
I fixed it myself... I disabled the "Exit Time" from animator properties and now the closing door animation works fine.