Including power-ups

In Angel Cakes, we developed a pretty basic collection system. In this game, we're going to be using the same principles for collecting items such as health and stars. Here is how they look in the game:

Actually, let's just take the script we used in Angel Cakes—if you recall, CollectableCake, and modify it.

For the stars, we should change the cakeValue variable to something such as starValue. Then, change the IncreaseScore() function call to the script you built before.

For the health, instead, we can erase the cakeValue variable, since each heart will grant just one life. Then, everything remains the same, just change the IncreaseScore() function call with this line:

FindObjectOfType<LivesCounter>().AddLife();

Save the script in another file, and you are good to go.

The next step is to create the prefabs for such collectables and make sure that the Audio Source component, as well as a Collider 2D with is Trigger, checked.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset