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...