Assign a script to a variable?

I found this answer on the subject, but it would appear I’m doing wrong here.

In the scene I have an object called _LevelMaster with a script named “LevelMaster” attached too it.

I want my enemy’s to grab that script and set it to a variable so they are not constantly using .GetComponent.

in their script I have;

private var levelMasterScript		: LevelMaster;

It doesn’t spit out any errors, but when it’s time to grab from that script, something like;

levelMasterScript.enemyCount -=1;

I get NullReferenceException…

What am I doing wrong?

Ok I solved it.

I had to also assigned that variable in Start (). So I needed to add a line;

levelMasterScript = getLevelMaster.GetComponent(LevelMaster);

Seems to work fine now!

referenced from this answer;