Since I always want there to be only 1 game state manager; I created a singleton loop to ensure that there is only 1 instance of it at all times. I also create an event that will be called when updating the game state.
This instance then contains an enum with all of the different game states and a switch case function to switch between them. At the end of this function I invoke the event created before, so that other scripts can subscribe to the updating of the game states.
Since I had always hardcoded UI before this project I wanted to try my hand at creating systems that could be built upon later. Allowing new UI elements or new game states to be added without any hassle. I wanted to achieve this through creating a simple game state manager using a singleton and then subscribing a UI manager to this game state manager.
Since I also only ever want one UI manager I will also create a singleton loop to ensure that there is only one instance.
I subscribe a function that checks the current game state to the game state event, so that this gets run each time the game state updates.
Spawning is split up into to main parts:
Each Time a new enemy is spawned I increase the integer to represent that change and each time an enemy dies it will get decreased to allow the spawning of a new one. (not shown here)
Each enemy is spawned with the Transform function shown below, this finds a random index in an array of spawn locations.
The goal for this system was a simple method of choosing a random spawning position out of a number of predetermined positions. This system was worked on cooperatively with another team member in GP1. I was responsible for the spawning and he was responsible for AI pathing. After having spawned it should also look for a "patrol path" that is close to its spawn point and then follow this until having spotted the player.
After having spawned; the enemy needs to find a patrol path and to make this feel a bit more random and immersive I wanted it to choose one out of several paths. So that if several enemies spawn close to each other they might still patrol different paths.
On spawn the enemy has to:
This system is very reminiscent of the last one, since it basically functions the same. This code was added to the enemy prefab and will thus run once upon spawning.
The code finds all nearby routes to its spawn position; adds these to a list and then picks a random element in this list to be its "decided route". Inside of this route there is 3 empty gameobjects serving as 3 different transform positions to traverse. These gameobjects are then passed through into the AI pathing code which then handles the movement.
The system includes two seperate lists of scriptable objects. One for player skins and one for kayak skins. There can also only be one allowed instance of the system so I created a singleton loop.
In my start function I update the lists checking if there is any saved inventory data and then add the default inventory data.
The goal for this system was to give the player a way to change skins and create a system that keeps track of the players current collected skins. This was a collaborative effort with another team member, where I created the UI and inventory system for the skins and he created the save data for it.
The game only required two kinds of player skins:
The player had to be able to select these skins separate of each other in the main menu and then be able to play with them.
To create this system I wanted to use a list of scriptable objects to hold all necessary references and then pass these references through into the player prefab to change its texture.
Adding skins was the hardest part of this task, which was to be expected. This function would be placed on the different "buy" buttons in the shop menu and would add their referenced scriptable objects into the list.
This scriptable object first goes through a check to see which type it is and where it will be shown.
I created a temporary "item" so that the skin could be saved on the device and I then added this skin to its respective list, at which point I invoke an event to update my UI for skins so it gets the new skin.
This script was added to the skin selection UI and handled updating its contents & changing the material used on the player prefab.
I start by creating references to the different parts of the UI & initializing the code; initiating lists, updating contents. Essentially a start function.
I destroy all children to my seperate button holders for the UI. Each holder holds "icons" icons are a prefab but for this showcase they are more or less just buttons. Each icon gets instantiated and then edited to have the correct values (showing the correct text, having the correct skin reference). I then add a function to these buttons onClick event to apply their referenced skin to the player.
I check all buttons under each seperate list of buttons to find what button was pressed. After having found the pressed button I then assign its scriptable objects material to the "kayakMat" or "playerMat" to then assign this material to the player when loading a different scene.