Now we have our tripleshot powerup movement and cleanup taken care of let’s actually make it do something. We know we are going to be changing the attack on the player so it would make sense we introduce the action on the player. We will need to create a method in order to have our powerup communicate with the player and start the action. Simple on/off bool will do great.
Of course we will default this to false on our player to begin with and use this method to trigger when it’s active. Now back on our powerup script we need to do just that. To begin with we will need to tell our powerup script who the player is even so we can access it’s method. There are several ways to achieve this but I will simply be adding the player as a Player.
We will want to reference the script component on the player so grabbing that in start is a good idea, we should null check here it is good practice when trying to access another object.
Now our powerup script can access the player’s script and communicate with it. As long as we set it up. Don’t forget to Serialize the Player so we can drag and drop the player game object
We now need to tell our powerup what to do when it collides with the player and this is where that handy Tag system comes into play. We know the collision will be a Trigger as that’s what we have setup and it will be 2D so we just need to check when our powerup hits the “Player” tag and have it do something. In this case we want it to tell the player script to activate it’s method we set previously and then of course remove the powerup. We also need one of the objects to have a rigidbody and in this case I recommend the player otherwise each powerup created will need one.
Now at this point I would just recommend putting a Debug.Log message inside our players method we are trying to talk with to make sure it triggers properly.