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.

This is how your void start should look at this point.

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.

--

--

--

I am hard working Game development student learning as much about game development and unity as possible.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

My Oracle Interview Experience (Server Technology)

district0x Dev Update - June 8th, 2021

Four Signs You Should Become a Software Developer

Task2 of Hybrid Multi Cloud launching a web server using terraform and aws(EFS)

Building Full-Stack Applications Using Angular CLI and Nx

How Docker & Containers Can Make Deployment A Picnic

What to do When the Client Knows Nothing About Websites

Example Temple for Submit in Upwork

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jake Boere

Jake Boere

I am hard working Game development student learning as much about game development and unity as possible.

More from Medium

Creating the UI Manager

Calming your users with loaders

A screen showing a loading bar

Integrating Google maps static API with Unity app

Technologies for Video Game Production