i have added a animator to the enemy prefab and i want to make the animation change when i hit it in the collision ( its **** out ) please can someone help me:(
i tried to make a new var eanim : Animator.... and call it in the start ect... but wont let me drag the ememy animator into the slot
how can i fix this please.
outline what i want to do i want to coll with the enemy and have the enemy that i hit change to death animation.
var Player : GameObject;
var Gravity:float = 2;
var speed:float = 2;
var enemytrans : Transform;
var enemy: GameObject;
public var jumped = false;
var anim : Animator;
function Start () {
while (true) {
yield WaitForSeconds (Random.Range(3, 0));
enemy = Instantiate(enemytrans).gameObject;
}
anim = GetComponent(Animator);
}
function Update () {
Player.transform.position.x = -4.325;
if (jumped == false){
anim.SetFloat("hf",0.0);
}
if (Input.GetButtonDown("Fire1") && jumped==false){
fire();
jumped = true;
}
if(jumped==true){
anim.SetFloat("hf",1);
}
}
function OnCollisionEnter2D(coll: Collision2D) {
if(coll.gameObject.CompareTag("ground")){
anim.SetFloat("hf",0.0);
jumped=false;
}
*********if(coll.gameObject.CompareTag("enemy") && jumped==true){ **
fire();
jumped=true;
anim.SetTrigger("isdead"); <<<<<<<<<<<<<----- this is what i need help with ------
}
if(coll.gameObject.CompareTag("enemy") && jumped==false){
Destroy(Player);
}
}
function fire(){
Player.transform.Translate(Vector3(Input.GetAxis("Vertical") * speed * Time.deltaTime, 0, 0));
Player.rigidbody2D.velocity = Vector2(0,10);
}