Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 5.x 2D Game Development Blueprints

You're reading from   Unity 5.x 2D Game Development Blueprints Explore the features of Unity 5 for 2D game development by building three amazing game projects

Arrow left icon
Product type Paperback
Published in Sep 2016
Publisher Packt
ISBN-13 9781784393106
Length 252 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Francesco Sapio Francesco Sapio
Author Profile Icon Francesco Sapio
Francesco Sapio
Abdelrahman Elsayegh Abdelrahman Elsayegh
Author Profile Icon Abdelrahman Elsayegh
Abdelrahman Elsayegh
Arrow right icon
View More author details
Toc

Integrating the UI into the game


Now that we have our enemies ready to challenge the player, let's integrate the UI that we have created in the previous chapter into the game.

In particular, we are going to see how to integrate the Lives Counter and the Money Counter since they are the two core gameplay elements.

Integrating the Lives Counter

We need to integrate the lives counter for situations such as when an enemy reaches the end of its path, the number of lives of the player is decreased. This happens in the following way: the enemy triggers a function in the Game Manager when it has reached the end, and the Game Manager updates the number of lives in the Lives Counter.

Therefore, let's start by opening our GameManagerScript and adding another variable. This is required to store the LivesCounterScript reference, so that we can have access to the lives of the player:

private LivesCounterScript livesCounter; 

To get the reference, we can set the variable inside the Start() function:

  void...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime