Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Mastering Android Game Development with Unity

You're reading from   Mastering Android Game Development with Unity Build high-end Android games with Unity's advanced features

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781783550777
Length 352 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Siddharth Shekar Siddharth Shekar
Author Profile Icon Siddharth Shekar
Siddharth Shekar
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Introduction to Android Game Development with Unity3D FREE CHAPTER 2. Finishing the Perky Penguin 2D Game 3. Adding Player Character for an Action Fighting Game 4. Enemy Characters with AI 5. Gameplay, UI, and Effects 6. GameScene and SceneFlow 7. Gamestats, Social, IAP, and Ad Integration 8. Sound, Finishing Touches, and Publishing

Adding GUI for health and gameover


In the game scene, add three texts and name them enemyHealthText, playerHealthText, and gameOverText.

The enemyHealthText text is positioned, as shown in the following screenshot, with the anchor at the center and the font height set to 32. The rest are set to default:

The playerHealthText text is set at a position, as shown in the following screenshot, with text height changed to 32:

The text color has been changed to blue for the enemy and red for the player. The gameoverText text is set to the middle of the canvas, with text height set to 75 and the color set to a nice purple so that it is easily visible.

In the Text field, add the text GAME OVER!!!, as shown in the following screenshot:.

One thing we haven't seen yet is how to control the text by code. Let's see next how to do that.

In the gameScript script, add three public variables of type Text, as given the following code snippet. This will hold the text object from the Text UI elements created:

    public...
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 $19.99/month. Cancel anytime