i want my character to use the punch animation on colliding with the player but its not working this is the script
var Myself : Transform;
var AttackorNot : int;
function Update () {
if(AttackorNot == 1){
Myself.animation.CrossFade("punch");
}
}
function OnTriggerEnter(other:Collider){
if(other.gameObject.CompareTag("Player"))
{
AttackorNot = 1;
}
}
Myself is the main object which have this trigger
so i set this boolean function that if it will collide with the player the boolean will be 1
and in the update function i used this boolean function to run the animation on the main Object.
its not working.
whats wrong in it?
OK, this script needs a bit of cleaning up. First of all, don’t use CompareTag, just look for other.gameObject.tag and determine if it’s “Player”. Second of all, you will instead want the object with the “Player” tag to have isTrigger checked. Third of all, you don’t need to specify the gameObject your script is attached to, because the compiler defaults to it if a specific object is not given. Therefore, your “Myself” variable is redundant. Also, you should try using camelCase for variable names so that they show correctly in the inspector. So like this:
var myself : Transform;
var attackOrNot : int;
function Update () {
if(attackOrNot == 1){
myself.animation.CrossFade("punch");
}
}
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag == "Player") {
attackOrNot = 1;
}
}
I believe that should work. By the way, attackOrNot isn’t a boolean, it’s an int. 
Hope that helps, Klep