Calling the levelmanager for the brick script

Why do we use levelManager.BrickDestroyed(); instead of LevelManager.BrickDestroyed();

I could not find any lower case level manager script in the entire LevelManager script and was wondering why we take the lowercase version instead of the uppercase version when calling out to the LevelManager script.

Tim

Within the calling class, levelManager is a variable, where-as LevelManager is the class (type).

You define a variable of type LevelManager, which is named levelManager and then access the member variables/members of the class through that instance, e.g levelManager.BrickDestroyed().

The variable could be named anything you want, e.g.

LevelManager whizBangLevelLoader;

then use it like;

whizBangLevelLoader.BrickDestroyed();

Although, for obvious reasons, its typically good practice to name your variables relative to what they are / used for.

Thanks Rob I appreciate the quick reply!

Tim

1 Like

No problem, does that help?

You will come across static methods later in the course, in fact you may have already seen some used within Unity, these methods do not require an instance of the class to be created first, so for example;

Application.LoadLevel

In these cases, you would use the class name, not the variable name.

So, if the BrickDestroyed method was static for example, you would then access it via;

LevelManager.BrickDestroyed();

Hope this helps a bit further. :slight_smile:

Privacy & Terms