Blog 2 – Week 7
Working with the Power UpFor about the past two weeks I have been trying to perfect the power up script. I, like many others, do not know Unity very well so it takes time to learn all the different ways to do achieve the same outcome. A little background before discussing the way I have been able to get the power up to the point it’s at now. For the alpha of our game we wanted to have a power up that would destroy all bullets on screen with a slight cool-down for the enemy bullets. The idea was to use this power up in times of high stress and lingering doom. It worked wonderfully (at least for an alpha version of it) though some things didn’t work for the first iteration of this script. First way that I approached this task was to simply make an object called ‘PowerUp’ and then I would attach the Power Up script onto it which would hold the code enabling the desired action to take place. It seemed simple enough, attach a 2D Collider to the object and ensure that ‘Is Trigger’ is ticked. Within the script I assumed that I would just make it simply void OnTriggerEnter2D(Collider2D collision) within this, have it check if it collided with the player. If true simply destroy this object and destroy all bullets. I tried implementing some sort of cool-down within that but it would never trigger that cool-down (unsure why). I thought that using the access to the script that had the particular cool-down I was looking for, private EnemyShooting bulletCool; and then setting enemy cool down to the bulletCool would make this happen. It did not, it just gave an error that I can not remember right now. Needless to say with the simple code that I had implemented, we had the Power Up for alpha.
![]() I was satisfied with the outcome of the first run through of getting this Power Up implemented but I knew it wasn’t perfect. Our group, as well as myself, wanted the player to be able to collect the Power Up and choose when they wanted to use it instead of it being used immediately. So, back to the drawing board for me, I quickly thought that the best option would be to have a second script attached to a different Power Up GUI object. This script, UsePowerUp, would be the place the code for simply activating the power up once you collected it within the level. In order to get this to actually work though I needed to be able to setActive from the regular Power Up script and move the destroy bullets to the new Power Up GUI script. Up to this point these two scripts do actually work, but once you use the GUI power up and it gets deactivated for some reason I can not get it to activate again. The program does actually reactivate it when you collect another power up, but it does not show back up on the level. So still a work in progress but once one power up is solved then making more will hopefully come much easier. ![]() |


