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.
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.