Day 19: Christmas Pains w/ My Shield Lives
This pretty much had me twisted for several days, trying to figure out just how to get my shields working on my spaceship with how to code for both the “Player” script and the “UIManager”.
I had all kinds of thoughts going through my head at firsts, trying to piece together how to make the logic sequences work (being that it was Christmas weekend, I didn’t really want to ask for help but really get this one under my belt).
So after struggling through this challenge, I started asking myself questions to help me get in the right direction. Questions like, though obvious, who has the shield? So I began looking at the coding for what needed to happen on the player script. What belongs on the UIManager? To which I knew that the images of the sprites belonged there.
Then dealing with what I thought would be the easier task, I started with the UIManager script of placing down the method to which the lives of the shield be shown on the UI for the player as he is gaming.
Which probably is not a very efficient way of doing it, but because the images were not like the images of the player lives, it was the best I could figure out.
Now the most difficult part, after being pretty certain that my UIManager was setup right, was the coding for the shield behavior on the player (now altering it from being “do nothing on hit” with using the code “return;” to now setting up the shield to now have 3 lives when it is active, to then have one shield life (as well as shield image on the interface) be taken down one without having the lives of the player also go down…which took me what felt like brain gymnastics to get down.
So instead of showing you what I coded only which was to set the shield lives in an int of 3, then set up a public void method to then minus 1 shield life when hit when triggered, but then also update the UIManager through grabbing the component method, and then also being sure that if the shield was active, that after the method was accomplished to then “return;” as so the method would not continue down to remove my player’s lives.
Must say, it’s a relief to have finally of accomplished this small challenge…