Day 10–11/5/20
Another very productive day! Managed to complete the Phase 1 Framework of the Space Shooter Pro! I worked on fixing up my shields to actually properly change colors based on the current health of the shield ( 3 lives per shield). I also added the camera shake function whenever the player takes damage, added a thruster bar, and a secondary fire power up.
The biggest blockers I ran into today, were my shield functioning properly and set up my secondary fire power up. I had my core code for the shield functioning properly yesterday, but couldn't get the sprite to match up. It would function properly the first time through, but then any shields obtained after the first would hold the color of the previous color to start instead of reverting back to the initial starting color.
Shield
I ended up solving my shield dilemma by creating a set of if statements, (I know it should be converted into a switch statement, but I wanted to focus on getting the code to work first.) the if statements took the health count of my shield from a referenced function being called in my player script since this is where damage is being triggered. My next step was to set up a bool to by-pass the initial shield pickup as it was causing my program to crash. I’m not entirely sure what was causing my program to crash when interacting with a shield, but it seemed to have something to do with my first pass through. May have been some kind of interaction with my player script and shield script trying to change the color of the initial shield when it was already set to the color I wanted. Anyways, the bool seemed to solve that issue and allowed me to bypass the color change on the first pass through since the color was already set to the desired setting. In any shield interactions after the first interaction, the bool would be set to true and would now pass through my first if statement to reset the color back from the color of the previous shield. I also ran into a problem with the shield renderer not properly disabling when losing the shields 3 lives. It would still show up on the player but the shield was not actually still up to block incoming damage. My solution to this was to make sure to enable the sprite renderer whenever a new shield was obtained and to make sure to disable whenever the shield life dropped to 0 through either time or damage.
Thruster and Camera Shake
I’m gonna be honest here, I ended up watching video tutorials by Brackeys on these two. The thruster I had an idea of what needed to be done, such as creating a max value for my thruster and decreasing that value by x amount while the shift key was held down. But how to visually go about that, well… I was at a loss there. So to google I went and after looking at a few documents I decided I would take a break from reading and check out one of the videos. Very straight to the point and easy to follow. The video really cleared up some of the confusion about how I would go about creating a changing ui graphic such as a health bar or thruster bar. In your canvas you can create a parent object where you can store things like the fill bar as well as a border to enhance the look of your bar. Anyways in the parent object you would then add a slider component which you can then add your fill object into the fill rect. And now with a little bit of coding and referencing you have a thruster bar that keeps track of your energy left. I also implemented a cd system that when your thrust hits 0, you have to wait a couple of seconds before it starts recharging again.
For the camera shake, I have my code above. From there it is fairly straightforward. You have to add the script to the main camera, and then I highly recommend creating a place holder for the main camera in the inspector. Aside from that, you can now reference your camera shake function in your player script when you take damage.
Secondary Fire Power Up — The Ring
Oh boy… I was getting all kinds of funky messages and outcomes with this one. As you can see above I was creating 60 rings per second. To be clear, I only wanted one ring to spawn at the player location and to grow for about 2 secs, killing everything it touches. Anyways many hours later and a lot of fiddling with code I was able to make it happen.