What is quiz.GameObject?

In the lecture Gary sets some code:


and by way of explanation says this sets the gameobject to true / false. But what is the gameobject? I’ve had a look in quiz.cs and the only gameobject set up there is the answerButtons variable. I imagine Gary means the quiz canvas - but how does Unity/C# know to interpret gameobject as that particular element?


Hi kmamor,

Our Quiz class inherits from the MonoBehaviour class. This means that we have additional things in our class. One of those things is gameObject. gameObject references the game object to which our script component is attached.

With quiz.gameObject.SetActive(true);, we are able to disable the entire game object (including its components) instead of a single component.

The same applies to endScreen.gameObject.SetActive(false);. If endScreen is of type GameObject, endScreen.SetActive(false); would be sufficient.

Did this clear it up for you?

See also:

Hi Nina,

So anyscript.gameObject is referencing whatever gameObject the script is attached to as a component. In this case quiz.cs was attached as a component to the QuizCanvas and so quiz.gameObject is therefore referring to QuizCanvas.

Assuming that’s correct - thanks (again!) for your help - makes sense now.


Yes, that’s correct. :slight_smile:

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

Privacy & Terms