I have 2d firing animation. I want to create and move the bullets towards enemy and I want to make this happen when at a certain time of the animation. I can access to animation time by using:
soldierAnimator.runtimeAnimatorController.animationClips[1].length
Also I am using coroutine to do what I want. Is there any easier or effective way to do this?
void fireTo(Enemy e){
soldierAnimator.SetBool("isReloaded", true);
soldierAnimator.SetBool("isInRange", true);
StartCoroutine("waitIt", e);
}
IEnumerator waitIt(Enemy e){
yield return new WaitForSeconds(0.5f);
GameObject bulletGO = (GameObject)Instantiate(bulletPrefab, this.transform.position, this.transform.rotation);
Bullet b = bulletGO.GetComponent<Bullet>();
if(e != null) {
b.getTarget = e.transform;
}else{
DestroyObject(b);
}
}