Sitemap

Steps on how I Fix the bug of Score text in Unity.

3 min readMay 25, 2023

Objective: Fix the bugs in the score text in Unity3d.

Before doing anything let's see the code of UIManager.I want when the game start score to be zero

But When I play Editor it starts with 2 then 1 finally it is set to zero.

Press enter or click to view image in full size

The first step Let's go to the UIManager and see If we have changed our code in the start method.

Press enter or click to view image in full size

After this let's make sure our text has the right text in our canvas.

Press enter or click to view image in full size

In the next step let's see if we call UpdateScore, at the right moment, I have called this in the player script inside the AddPointToPlayer method.

Press enter or click to view image in full size

Now let's see if we call this method at the right time, I have called this method when enemy health reaches zero inside the enemy/AI script.

Press enter or click to view image in full size

But Enemy’s Damage method is called in the player script when we hit Enemy by using RayCast.

Note: When the game starts I don't shoot at the enemy but the text starts from 2 up to zero.

Press enter or click to view image in full size

In this step go to UIManager and use the Visual Studio tool tip<Reference for UpdateScore and expand to see where we call this method.

If you see here we call Update score in the wrong script and there is a variable called _aicount which updates the score every time we enable the enemy of the game.

I was like What, UpdateScore does not relate to Pool Manager, who put it here, and I was like it's Suleiman, myself so I delete it there.

Press enter or click to view image in full size

Let's play and see If we fix the bugs.

Press enter or click to view image in full size

This is how I fix this bug, see you in the next one.

--

--

Suleiman Abdullah
Suleiman Abdullah

Written by Suleiman Abdullah

My name is Suleiman Abdullah. I learn game development and share what I learn by writing articles. :https://ko-fi.com/suleimanabdullah

No responses yet