Hi guys,
I’m trying to trigger animations with the function OnTriggerEnter. I want the player to hit the button and trigger the door animation. I have included a little diagram of what I am wanting to do.
I’m using unity 5.2.
I’ve already tried the code below. I put this code on the door parent, with the animation applied to the door parent. But when the player hits the button it doesn’t trigger the animation.
Code:
using UnityEngine;
using System.Collections;
public class Door1 : MonoBehaviour {
Animator animator;
bool doorOpen;
void Start()
{
doorOpen = false;
animator = GetComponent<Animator>();
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
doorOpen = true;
DoorControl ("Open");
}
}
void DoorControl(string direction)
{
animator.SetTrigger (direction);
}
}
I’ve also tried other code with it attached to the button and the collider set to “is trigger”, but that didn’t work either.
I would truly appreciate any help.
Thanks in advance.