- Home /
Question by
Andrewlo3 · Dec 06, 2013 at 06:07 PM ·
fireparticle emitter
How to turn off and on particle system [script]
I have a campfire gameobject with the standard package flame particle emitter attached to it. I want the flame particle emitter to turn on and off when I press "E" within the box collider trigger area around the fire. Here is my code (in javascript) so far:
#pragma strict
var theFire : Transform;
var flame : ParticleEmitter;
private var drawGUI = false;
private var fireIsOff = true;
function Start () {
}
function Update () {
if (drawGUI == true && Input.GetKeyDown(KeyCode.E))
{
changeFireState();
}
}
function OnTriggerEnter (theCollider : Collider) {
if (theCollider.tag == "Player")
{
drawGUI = true;
}
}
function OnTriggerExit (theCollider : Collider) {
if (theCollider.tag == "Player")
{
drawGUI = false;
}
}
function OnGUI () {
if (drawGUI == true)
{
GUI.Box(Rect(Screen.width*0.5-51, 200, 102, 22), "Press E to use");
}
}
function changeFireState () {
if (fireIsOff == true)
{
theFire.animation.CrossFade("On");
fireIsOff = false;
yield WaitForSeconds(5);
}
if (fireIsOff == false)
{
theFire.animation.CrossFade("Off");
fireIsOff = true;
//yield WaitForSeconds(3);
}
}
screen shot 2013-12-06 at 11.37.20 am.png
(478.1 kB)
Comment