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
Procedural Content Generation for Unity Game Development

You're reading from   Procedural Content Generation for Unity Game Development Harness the power of procedural content generation to design unique games with Unity

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785287473
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ryan Watkins Ryan Watkins
Author Profile Icon Ryan Watkins
Ryan Watkins
Arrow right icon
View More author details
Toc

Adding a weapon pick up


Now, we can move on to adding the logic that will run the player pickup of the weapon object. This will be very similar to the other player pickups except that the weapon will need a few special considerations. For one, the weapon will need to be in the same screen location as the player at all times so that it can animate appropriately.

Let's begin by opening up the Player.cs script where the current player pickup logic exists. We are going to add a few new variables that will hold references to our weapon and some of the images that we will use to make the display icon. As stated earlier, we will create a display icon on the screen that will show the weapon that the player has in their inventory. Add the following lines to the beginning of the Player class definition:

1 private Weapon weapon;
2 public Image weaponComp1, weaponComp2, weaponComp3;

We will then edit the OnTriggerEnter2D function. We need to add a condition that will allow us to handle against colliding...

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