Unassigned Reference Exception

Unassigned Reference Exception. Can’t figure it out. Of course any help would be appreciated.
See attached code.[149930-sparks01lgb.txt|149930]

I believe you need to set the SmokeSparks1 variable in the editor. By selecting the game object with the sparks script you should see the inspector on the left. In the inspector you should see a field for the “SmokeSparks1” particle system.

If the particle system is on the same game object as the script instead of assigning it manually you can do something like:

void Start()
{
   SmokeSparks1 = GetComponent<ParticleSystem>();
}

if it’s in a child try GameObject

void Start()
{
   SmokeSparks1 = GetComponentInChildren<ParticleSystem>();
}

When you get the NullReferenceException it should tell you exactly what line of code in your script where the exception occurred. This can help you determine exactly what the problem is.