I want to show an accident of Character with car. so I wrote this code and in update function I wrote this...

        if (Once) {

                    Criminal.GetComponent<Animation> ().Play ("Running"); // after collision This animation will work
                    Criminal.GetComponent<BezierMover> ().enabled = true;
                    TrafficCar.GetComponent<BezierMover> ().enabled = true;
void OnCollisionEnter (Collision col)
    if (col.gameObject.tag == "Vehicle") {
        if (!Criminal.GetComponent<Animation> ().IsPlaying ("Stumbling"))
            Criminal.GetComponent<Animation> ().Play ("Stumbling"); // Animation for Accident
        Criminal.GetComponent<BezierMover> ().enabled = false; // to Deactivate the AI Script.
        TrafficCar.GetComponent<BezierMover> ().enabled = false; //to Deactivate the Trrafic cars Path Script.
        Once = true; 

but after first animation second animation should work but this is not happening..

  • \$\begingroup\$ Which Animation is supposed to be the second animation?. And, is your if condition inside Update function? \$\endgroup\$ Jan 25 '17 at 6:39
  • \$\begingroup\$ @AdityaYadav Animation in if condition is second animation and yes it is inside update function... \$\endgroup\$
    – user44356
    Jan 25 '17 at 7:23
  • 2
    \$\begingroup\$ Did you try switching the 2 animations to check if "Running" animations works well? Did you try commenting the Criminal.GetComponent<Animation> ().Play ("Stumbling"); line to check if it is not due to launching animation when previous animation still running? Did you try putting a breakpoint in the update function to check if Once is still set to true? \$\endgroup\$ Jan 25 '17 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.