Unity: Creating a UI manager
Objective: We need to create a new script that updates the score text to add 10 to the score every time an enemy is destroyed.
To start we need to create a new script and name it UI manager, then open it. Then we need to create a variable that holds the score text and assign what we want it to say in void start.
Next, we need to create a function that updates the score with an integer that holds the player score. In the function we need it so that it shows the score plus the players score.
Next, in our player script we need to create a score variable there and make a new function that handles adding the score with an integer that holds the points that player gets. In the function we need to make it so the players points add and equal to the score and then communicate with the UI manager to show the score. To do this you’ll first need to create a UI manager variable and then in void start we need to find the game object that holds the script for the UI manager, then null check to make sure the game has it when it starts up.
Now back down to your add score function in the player script you need to use the UI manager variable you made then access the update score function from the UI manager and put the amount of points you have inside the function.
Lastly, in the enemy script we need to communicate to the player that wee need to add the 10 points when it gets destroyed using the laser. So, to do this you will need to create a player variable and make it in void start the the player variable equals to the game object that holds the player script.
Then, in your else if statement for the collider make an if statement that’s if the player doesn’t equal null the player uses the add score function and adds 10.