[SOLVED]Need OnTriggerEnter Help
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.
Did you set the tag on player in Inspector? @Ljrnet
Answer by Ljrnet · Nov 06, 2015 at 11:20 AM
No that didn't work :( but thanks mate.
I fixed the problem by upgrading to unity 5.2.2 but then it cause this problem:
When the player hits the trigger it says this in the console. Parameter type 'Open' does not match. UnityEngine.Animator:SetTrigger(String).
I fixed that problem by changing the parameter on my animation from an int. to a trigger.