OK so I've been looking into "Animation Events" not that I understand how they work but it might be what I need for my animation problem. I have a UFO that takes off from a hill when the player gets within a certain distance, but whay I want is about partway thought the fight animation for a small explosion to occure on the side of the UFO and then for it to explode an "Destroy game object" at the end of the animation cycle??
Here is my code so far:
var UFOsound : AudioClip;
var escapeDist = 0.4;
private var player : GameObject;
function Start(){
player = GameObject.FindWithTag("Player");
}
function Update(){
if(Vector3.Distance(transform.position, player.gameObject.transform.position) < escapeDist){
animation.Play("UFOtakeoff");
audio.PlayOneShot(UFOsound);
}
}
Everything works great but I can't figure out how to get the small explosion to happen mid flight in the animation, I'm thinking animation event but I've no clue how that works, been looking for an example. Unity's code reference does not really explain it in a way I can understand.
So I guess I would need two animation events, one for the explosion mid flight and another event for at the end of the animation, that is if I understand that part corectly. If I could somehow code in a dead replacement that would be super cool too, but again, my coding knowlede is not that great yet, still trying to wrap my head around how a lot of it works... getting there though, slowly, Oh so slowly :)