Create UI Score System in Unity

Show current score to the User

Rusben Guzman
2 min readJun 15, 2021

Objective: Add score when the player destroys an enemy and show the current score in the UI

Go to the hierarchy and right click to create a UI > Text element, go to the Rect Transform component and use the anchors to place the text in the top right corner.

Go to the Text Component and adjust the font, color, size and any property until the text looks good for you.

Now create a UIManager C# script.Within the script we have to use the namespace UnityEngine.UI in order to access the UI elements through code. Next declare a serialized Text variable _scoreText and assign the reference in the inspector.

In the UIManager script create a public function to update the score text receiving the points as a parameter.

In the player script we have to declare an _score variable then create a function to update the score and in the enemy script we just have to call the function when the enemy is destroyed.

And that’s it! We have a score text which is updated each time we kill an enemy.

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet