Welcome to my next work update for my work on 310Games’ The Krilling! This week will be a lighter week as release is imminent, so we are just adding some final touches. I have been tasked with implementing a quick new UI element to tell the player how many possessables they have access to and how many they have actually seen/used.
Here is what the UI element will look like as well as the description of what it will do:
First, I made some large cubes to indicate the areas that will appear on this UI. I will make them invisible and only act as triggers, but before that, here is a picture just to show the area covered:
Each of these cubes also has its own tag to indicate the area of the map it is, which will be helpful later. Next, using the above mock up of the UI art as an example, I added all the elements I could think I will need to use/will be needed for art assets later. Here is where that landed for now (may change later if art demands change):
Notably the green flame being used right now will likely change, it was just already there for our previous score counter (which I am reusing) so I figured I could use it to help with the placement of objects.
Now, into programming. I will explain my initial plan first, and then will walk you through what I actually did. I plan to make a game event that will trigger simply whenever the player enters one of my new trigger zones. This new UI element will be listening for this game event, and will receive information about which zone it is so it can change what it displayed. I will also have this UI element have serialized lists for each of the quadrants that exist and the possessables that they contain. Using these lists, it will display the total number of possessables in the area (on the right). Then, whenever a possessable is entered by the player, this UI element will also listen for a game event which will tell it which object was possessed, and then it can add a tally to the left number if it is the first time the player has possessed that object. That is the plan, now let’s see it in action!
I started with the game event triggering in the separate quadrants, as that should be fairly simple. Here are two screenshots of the game event and its args as well as the simple code placed on the triggers themselves:
And it works! I could show you a screenshot of the debug log showing and tallying up, but I think you can trust me on this one. Now, I will make the UI listen and change the title text according to the quadrant the player is in!
First, I made the script listen for the new game event, then I made a switch statement to check for the proper tags and change the text of the title object accordingly! Here is the code and a screenshot of it working!
So the title works now! Next, to get one of the numbers working on the HUD I will make a serialized list on each quadrant that can be passed with the other trigger enter data and be accessed to set the total number of possessables in that area. Here is an example of one of the lists, the code added to set the number, and a picture of it working!
So, now all that needs to be done is setting up a way of knowing which possessables from each of these areas the player has used so far. The solution (as it has been a couple times now): a dictionary! I implemented a dictionary that keeps a list of each possessable the character accesses in each quadrant and then I just display the count of those lists in each quadrant. I will show the final (for now) version of the code for this UI element as well as a screenshot of the count working!