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);
}
}