Changing animation of the hearts of the symbolic lives counter through the script

In this recipe, we will go even further than we went in the previous recipe. Here, we will see how we can control the Animator controller through a script. In this specific case, you will learn how to change the speed of the controller according to the number of lives that the player has left. In fact, we want to make the hearts beat at a normal speed when the player has all his lives intact and beat faster when the player has fewer lives.

Getting ready...

In order to get started, you should have completed the previous recipe, Animating hearts of the symbolic lives counter, because you need to have all the hearts animated through an Animator controller, called HeartAnimationController ...

Get Unity UI Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.