Currently there are no tell-tale signs when the Player
has filled their inventory. Sounds won’t be added until later down the line, so
rather than just placing a Debug.Log statement to output it to the console, I
figured that now was a good time to add a notification telling the player that
there were no more inventory slots available. Up to this point, mining with a
full inventory would still destroy the rock, just that no item would be
received, I decided to change this while I was at it.
To start with, I added a check within the Mining.cs
script, whenever a target has been hit by the ray cast, then the player’s
inventory will be checked using the function CheckInventory. If there’s space,
then the player can deal damage and upon destroying the rock, the UI is updated,
and the Player’s inventory is checked again. The inventory check is simple: if
the inventory is full, then a trigger is set to true within the animator on the
inventory, and this will trigger the inventory full notification once, which
plays the animation. Whenever I’m developing a system such as this, especially
where many events are being called from multiple scripts, I try and think about
the best way to do it so that events are only fired when they need to be, and
if possible, not from multiple places. This not only helps with optimisation
but also with problem solving later down the line because it reduces the
possible places that something is being called from. Because of this way of
thinking, I try to develop systems that don’t require to be called every frame,
but rather from a chain of events.
Moving onto the next feature, I added a depth counter.
This counter will act as ‘high score’ system as well as giving the player some
feedback about what level of danger they are in. The only problem with this
system is that because the level is generated from a sprite, I can’t modify the
world position. To combat this, I have had to get the player’s y position and
subtract 152 from it to set the depth count to zero. I also would have
preferred that the depth counter was a positive number, but I was not able to
achieve this.
The final update of this section was a bugfix with the
mining. This bug occurred if the player changed their mining target without
letting go of left-click. The problem: Ores would not regenerate health unless
the Player stopped mining completely, and this bug was a tricky one to fix. The
solution that I found for it was to store the Player’s target (which is already
stored in a variable) into another variable called previousTarget. This way, whenever the player selects a new target,
the previous one will regenerate health. At first, I didn’t think this would
even work, as when the player’s inventory was full, I was getting a reference exception error, which stated
that an object was still trying to be referenced even though it had been destroyed.
However, I managed to fix this by setting the previous target to null after
regenerating health and checking if
(previousTarget != null) meaning that the code would only execute if there
was a target in the scene.
No comments:
Post a Comment