Happy Halloween🎃! Today is day 12 of my 74 day challenge to become a Unity Game Developer.
Today was…..hmmmm. Today was good overall, definitely worked on a few different features however, I ended up stuck on a couple for a while🙃. I guess it is a full moon after all.
Let me show you what I mean…..
So, there’s a couple things going on here.
- Ideally, the super laser should work. (UPDATE: Luckily, while I was writing this, I figured out what was wrong! I’ll explain down below).
- At the start of the game, there should be no shield image displayed (it has since been fixed). When the player collects a shield powerup the ui should update with the appropriate shield image. When the powerup is initially collected there should be 3 lit up shields decrementing by 1 each time the player takes a hit. The image should deactivate once all 3 are used up.
At first, neither of those things were happening. Happy to have it down to one!
Here is a walk through of some of the things I did to try and resolve these issues, starting with the super laser.
- Looking at what was happening when it fired I thought that it probably had to do with how the prefab was set up as it was firing as intended just the physics weren’t applying correctly. The first thing I did was check to make sure the rigidbody 2d and the collider2d were on. They were. I also checked to make sure that all of the references to the object were in the appropriate places for the prefab. Double checked that the laser script was attached and active. At this point, the super laser should have identical behavior to the regular laser with the only difference being its prefab. I checked to make sure the laser behavior in the player script was also correct and could not find any issues. In the end, I forgot to tag it as “Laser” and so it was not triggering properly in the Enemy script.
Here’s some of the things I checked for with the shields.
- The intended behavior for this function should be that when isShieldsActive is equal to true than it should set the image in the UI to active, and update the image by passing in the int value of the number of shields remaining into an array which should than display the corresponding image in the given index. The first issue I had with this was that the index would go out of bounds for the array used to pass in the correct image on the UI. I needed to put something in place that would keep the int used for the number of items in the array within the bounds of the array. I addressed this by using if statements. What I realized next is that although the UpdateShield() gets called and updated, the image is not activating or deactivating properly. I also tried changing the syntax to enable the image instead of using the SetActive(). I have a feeling it is something simple I’m overlooking. If it is, please don’t judge me! Still a noob…but if you do see it, feel free to help a sister out :-) Will work on finding a solution tomorrow. (UPDATE 11/01/20: Though its still not doing exactly what I want it to do, I at least figured out why is wasn’t activating the image on collect and it is because I was calling the ui UpdateShield() when the player gets damaged. I knew it was something simple! The issue I’m having now is that the image still isn’t showing the right index in the array even though the index is correct. i.e. _shieldsRemaining = 3 which should then call _shieldSprite but showing ?. . It’s probably the order in which things are executing and another simple thing I’m overlooking. Hoping to figure it out sometime today and provide an update in my post tonight.)
Challenge I faced:
- See above. Also did not get to the pumpkins or animations. Will work on those tomorrow. May have to convert this from a Halloween theme to a Thanksgiving theme hehe.
Will be at it again tomorrow. See you then.