Script not working, no compile errors...On Trigger Enter

I’m trying to get my enemy to attack me when it comes into contact with my player. Here is the script on the enemy: (Enemy has a collider and is ticked “trigger”) This enemy also has an AI script on it that makes it run towards the player… Could that be causing this??

var yourAnimation : String; ///I put "attack1" here and its attached to the zombie
 var zombie : GameObject; ////I put my zombie/enemy gameobject here....
 function OnTriggerEnter (Other : Collider){
 if(Other.gameObject.tag == "Player"){

My Player has a collider attached without the “is trigger” box checked. My player is tagged PLayer. I also tried this the other way around to no avail. When my player comes into contact with the enemy it does not play the animation. Any ideas on my script?? Again I have no compile errors on runtime.

My Enemy AI script just in case its helps:

var Player : Transform;
 var MoveSpeed = 4;
 var MaxDist = 10;
 var MinDist = 5;
 function Awake(){
Player = GameObject.FindWithTag("Player").transform;

 function Start () 
 function Update () 
     if(Vector3.Distance(transform.position,Player.position) >= MinDist){
          transform.position += transform.forward*MoveSpeed*Time.deltaTime;
          if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
                 //Here Call any function U want Like Shoot at here or something

As per the documentation, one of the collider gameobjects must have a rigidbody attached for trigger events to fire.


try replacing




Because in your code there was a string yourAnimation which actually is attack1 (this is your string’s value), but since you use “yourAnimation”, it’s not going to work because computer thinks that you are looking for animation called yourAnimation instead of an animation with name equal to the value of string yourAnimation