I’m a beginner in Unity, I’m following a tutorial book and everything is going well so far, except for this problem. I’m getting the NullReferenceException for this code:
function lightFire()
{
var campfire : GameObject = GameObject.Find("campfire");
var campSound : AudioSource = campfire.GetComponent(AudioSource);
campSound.Play();
var flames : GameObject = GameObject.Find("FireSystem");
var flameEmitter : ParticleEmitter = flames.GetComponent(ParticleEmitter);
flameEmitter.emit = true;
var smoke : GameObject = GameObject.Find("SmokeSystem");
var smokeEmitter : ParticleEmitter = smoke.GetComponent(ParticleEmitter);
smokeEmitter.emit = true;
Destroy(GameObject.Find("matchGUI"));
}
What happens when I press the Play button: only the sound plays but nothing happens with the particles and the GUI doesn’t disappear.
Any help would be appreciated.
I got it. The book is a bit old (for Unity 3.5 or something) and the particle system has changed, so I added the Ellipsoid Particle Emitter manually and I no longer get an error, and it now says “True” to the “Did we find a particle emitter?” debug.
Now it still doesn’t work though; the particles are either on or off, the script doesn’t change that. Only the sound works fine but the particles and the Destroy/GUI don’t work and the text hint stays the same before and after picking up the matches.
Am I missing something else? And do I have to remove the Particle System and leave only the Ellipsoid Particle Emitter?