Which 'scoreboard' is being referred to?

Dear GameDev.tv Team,

I have a question about what Ben means by the term ‘scoreboard’ in the section of the video noted in the attached screenshot.

At about 6:06 into the video, Ben says that all of the enemies (with the Enemy.cs script attached) are finding references to the ‘scoreboard’. I am confused as to specifically what does he mean by ‘scoreboard’ because we have a game object by that name, along with code-line 11 (ScoreBoard scoreBoard;), and a script named ScoreBoard.cs.

Line 17 sets our variable scoreBoard equal to FindObjectOfType. I think that this is setting our variable to the full value of the ScoreBoard class? But then in the screenshot that I’ve attached, Ben is drawing lines from the enemy ships down to the game object named Canvas>Text (which he will later rename). I think he is actually referring to the ScoreBoard class which is attached to the game object (named ScoreBoard.cs) - but this is confusing to a beginner.

I know it may be good practice for a seasoned programmer to reuse words - but for me it would be better, in terms of learning, if the class, the variable and the game object did not all have the same name (that is, same name when spoken b/c I can’t hear the capital letters in the voiceover instruction).

If possible, please clarify which ‘scoreboard’ is being referred to in the screenshot?

And I would also be curious to know why the practice is to name things in C# like this: ScoreBoard scoreBoard;

Thanks!

Hi,

That’s a good question. Thank you for asking.

With FindObjectOfType, we look for components attached to an active game object in the current scene. Ben means the ScoreBoard componen, not the game object which happened to be named “Score Board”.

And I would also be curious to know why the practice is to name things in C# like this: ScoreBoard scoreBoard;

Because we have only one ScoreBoard object. There is no need to give the variable a unique name which might confuse us in the future. Nevertheless, if you have a better idea, please feel free to rename your variable. :slight_smile:

If possible, please clarify which ‘scoreboard’ is being referred to in the screenshot?

That’s not possible because your screenshot does not show a ScoreBoard component. Furthermore, FindObjectOfType returns the first ScoreBoard object it finds, what ever Unity defines as “first”. As long as there is only one ScoreBoard component in your scene, it’s the one which gets returned.

Did this clear it up for you?

Hi Nina,

Thank you for the fast reply. What you say is helpful! To be clear, by ‘ScoreBoard component in [my] scene’ - do you mean the ScoreBoard CLASS defined in the ScoreBoard.cs script?

Thanks!

do you mean the ScoreBoard CLASS defined in the ScoreBoard.cs script?

In C#, classes are blueprints. We almost never use classes but objects which were created from classes.

If you find this a bit hard to understand: Imagine that a class was a blueprint of a car, and the object was the car. You cannot drive a blueprint, but you can drive a car.

I meant the/a ScoreBoard object. In Unity, when you assign a script to an Inspector, Unity automatically creates an object from that script/class. In the context of Unity, we call these special objects components.

Hi Nina,

Thank you again. That explanation helps a lot!

:slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms