Need help to better understand why we need to use "FindObjectOfType"?

If score is set as a public variable (and supposedly accessible by any class or method), and having furthermore defined scoreKeeper as Type ScoreKeeper, why do we still need the statement “scoreKeeper = FindObjectOfType();” ?

Because in the class you declare the attribute of type ScoreKeeper but you don’t have an instance of it.
So the teacher use FindObjectOfType to find the instance of the ScoreKeeper in the scene and use it for update the score.

Privacy & Terms