Explosion Effects in Unity through Animation

  • Go to the animator window and it should show the following pattern if the animation has been applied correctly on the game object.
  • Here, right-click and add an empty state (rename as per choice) which is going to behave as a bottleneck for the animation effect to pass through.
  • Again, right-click on the newly created state and make it a default state.
  • Make a transition from the new state to the animation state.
  • Select the “+” symbol in the animator window and add a trigger parameter with a name of choice. (Bool can work also with setBool( )).
  • Click on the transition arrow in between the newly created state and the animation to verify what will happen when the state shifts to the animation. (This is the hook!)
  • First, get the handle of the animator component in the script.
private Animator _explosion;
  • Use the SetTrigger(“xxxx”) method to enable the animation. the argument in this method is the name of the trigger that was created in the steps above.
  • First, untick the “Has Exit Time” option that basically means a state will only get transferred after full completion.
  • Second, reduce the speed of the game object that gets destroyed.
  • Third, disable the collider component as soon as the collision occurs so that the other object does not get affected if there are collision penalties set in the game.
  • Fourth, the animation needs a few seconds to get displayed and therefore, delay the destruction of the object for a few seconds.
public void _TriggerAnimation()
_speed = 4.0f;
this.gameObject.GetComponent<Collider2D>().enabled = false;
Destroy(this.gameObject, 1.5f);

  • Finally, call the method in the right place.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store