I’m trying to get a model to stop walking, when it enters a Collider trigger, then play the attack animation…I have this script and a circle Collider on the model set to IsTrigger…when it hits the player its supposed to stop, but doesn’t…The Player is tagged with player…the animation state is set to a bool,when the walking animation is played the bool is false, when the trigger is touched, the bool is true, then the attack is played.
What am I doing wrong?..The model walks right into the player and the trigger isn’t working, until I back off the player a little, then it plays…the trigger just isn’t triggering like its suppose to. this is all happening on a NavMesh and I’m using Unity 4.6
.
using UnityEngine;
using System.Collections;
public class zombieIdleTrigger : MonoBehaviour
{
Animator anim;
NavMeshAgent agent;
Transform Player;
void Awake()
{
anim = GetComponent<Animator>();
agent = GetComponent<NavMeshAgent>();
Player = GameObject.FindGameObjectWithTag("Player").transform;
anim.SetBool("zombieStop",false);
}
void OnTriggerEnter (Collider other)
{
if(other.gameObject.tag =="Player")
{
anim.SetBool("zombieStop",true);
agent.speed = 0;
Debug.Log("ENTERED");
}
}
void OnTriggerExit (Collider other)
{
if(other.gameObject.tag =="Player")
{
anim.SetBool("zombieStop",false);
agent.speed = 3;
Debug.Log("EXIT");
}
}
}