Animation Play On Bullet Shot

Hi everyone! I tend to make “on bullet shot” animation playing dependency which means I need shooting animation being played EVERY TIME AND ONLY AFTER BULLET SHOOTS OUT. Here’s my script:

private var _animation : Animation;

var Bullet : Transform;

var Speed = 500;

var spawnPoint : Transform;

var Counter = Time.deltaTime;

var RateOfFire = 0.250000;

var target : GameObject;

function Shoot()
{

  yield WaitForSeconds(0.1);

  Counter += Time.deltaTime;
  if(RateOfFire<Counter){
  var shotRapid = Instantiate(Bullet, spawnPoint.transform.position,
  Quaternion.identity);
  shotRapid.rigidbody.AddForce(transform.forward * Speed);
  Counter=0;
  }
  if (Counter>=0){
  target.animation.CrossFade("shoot1",0.2);} 

}

The problem here’s that animation still can randomly be played before bullet gets out or after. I’ve also tried on speed dependency (if Speed >=0), but it doesn’t work properly. I think I need to identify when bullet starts its’ movement and tell animation “shoot1” to play after that. But how can I do this? Thanks in advance :slight_smile:

i guess the problem at counter = 0;

function Shoot() {

    yield WaitForSeconds(0.1);
     
    Counter += Time.deltaTime;
    if(RateOfFire<Counter){
    var shotRapid = Instantiate(Bullet, spawnPoint.transform.position,
    Quaternion.identity);
    shotRapid.rigidbody.AddForce(transform.forward * Speed);
    Counter=0;
    }
    if (Counter>=0){
    target.animation.CrossFade("shoot1",0.2);}
     
    }

try this function…

function Shoot() {

    target.animation.CrossFade("shoot1",0.2);

    yield WaitForSeconds(0.1);
     
    Counter += Time.deltaTime;
    if(RateOfFire<Counter){
    var shotRapid = Instantiate(Bullet, spawnPoint.transform.position,
    Quaternion.identity);
    shotRapid.rigidbody.AddForce(transform.forward * Speed);
    Counter=0;
    }
    
     
    }