- Home /
This question was
closed Apr 06, 2013 at 11:40 AM by
whydoidoit for the following reason:
Duplicate Question
Question by
Frederik283 · Apr 05, 2013 at 06:45 PM ·
javascriptparticles
gameObject.Find() returns null.
Hey there!
I am trying to create a script for a smokegrenade, the Smokegrenade contains a particle emitter which emits a thin trail of smoke as the grenade is fired and then after 3 seconds the Smokegrenade's child object 'SmokeCap' is supposed to start emitting the thick smoke, but for some reason the variable GrenadeMuzzle that i created on line 6, returns null instead of returning an object, am i doing something wrong?
Here is my Javascript:
#pragma strict
var GrenadeTime = 0f;
private var oneSecond = 0.001f;
var duration : int = 20;
var despawnTime : int = 60;
var GrenadeMuzzle = gameObject.Find("SmokeCap");
function Start () {
}
function Update () {
print(GrenadeMuzzle);
GrenadeTime += oneSecond + Time.deltaTime;
print("GrenadeTime: " + GrenadeTime);
if (GrenadeTime >= 6) {
particleEmitter.emit = false;
GrenadeMuzzle.particleEmitter.emit = true;
}
if (GrenadeTime > duration) {
GrenadeMuzzle.particleEmitter.emit = false;
}
if (GrenadeTime > despawnTime) {
Destroy(this.gameObject);
}
}
Comment
Best Answer
Answer by Dracorat · Apr 05, 2013 at 06:50 PM
I think you need to make line 6 just:
var GrenadeMuzzle;
And then in the Start method, use:
this.GrenadeMuzzle = gameObject.Find("SmokeCap");
I say this because I don't think the child objects are going to exist before the object has been set up.