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! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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
 Sapio Sapio
Author Profile Icon Sapio
Sapio
Abdelrahman Elsayegh Abdelrahman Elsayegh
Author Profile Icon Abdelrahman Elsayegh
Abdelrahman Elsayegh
Arrow right icon
View More author details
Toc

Adding enemies


To make our level more exciting, we need to add some enemies to the level. We can use the sprites under Platformer Pack | Enemies and start by creating the snail enemy.

Just like how we animated our player, we will do almost the same for the enemies; drag and drop both snailWalk1 and snailWalk2 into the scene to create the animation. Then, rename the object to Enemy1, scale the object to (-3,3,3), so that it fits the dimensions of our game level, and then place it on the first platform of the level. Finally, add a box collider that fully encloses the sprite and a rigid body with its FixedAngle variable set to true. As a result, the Inspector should look like the following:

Before going forward with the enemies and their code, we first need to create some obstacles to place in their way. In fact, our enemies will change direction every time they collide with an obstacle.

We can achieve this by dragging boxAlt from the Project panel under Platformer Pack | Tiles inside the scene...

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 £13.99/month. Cancel anytime
Visually different images