Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Create only one Instantiated Object

$
0
0
Okay guys - I can't figure this one out. I have a day night cycle going by the rotation of the directional light, and at night I need a fire particle system prefab I have to start up, and during the day I need it to go away. How I have it set up right now, it creates to many instances and possibly would kill the game object rather than the instance? I need this Day- No fire/ Night - Fire cycle to continue for an infinite amount of time. Here is the scripts I have This one is for the rotation of the light and to tell something that the rotation is correct for Day time or Night time #pragma strict public static var TimeOfDay : float = 0.0; public static var LightRotation : float = 0.0; function Update() { transform.Rotate(Vector3.right / 3.0); LightRotation = transform.eulerAngles.x; if (LightRotation <= 150) { TimeOfDay = 0.0; BroadcastMessage("KillFire"); Debug.Log(TimeOfDay); } else if (LightRotation >= 150) { TimeOfDay = 1.0; BroadcastMessage("StartFire"); Debug.Log(TimeOfDay); } } This is what I have on the empty object to create the fire instance #pragma strict public var prefab : GameObject;; function KillFire(){ Destroy(prefab); } function StartFire(){ Instantiate(prefab,transform.position, Quaternion.identity); } Any and all help would be greatly appreciated. Thank you!

Viewing all articles
Browse latest Browse all 1875

Trending Articles