The fire is turning on and off properly when I press “E”, my only problem is the yield WaitForSeconds part. I want the fire to stay on until I turn it off and stay off until I turn it on. Right now it only stays on for 5 seconds, but if i remove the yield WaitForSeconds(5) part, the fire won’t turn on at all. Here is my javascript.
*edit: I can always change the WaitForSeconds to like 10,000 seconds, but I’m sure there is a more practical way
#pragma strict
var theFire : Transform;
var flame : GameObject;
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");
//flame.emit = true;
//particleSystem.enabled = true;
flame.active = true;
fireIsOff = false;
yield WaitForSeconds(5);
}
if (fireIsOff == false)
{
//theFire.animation.CrossFade("Off");
//flame.emit = false;
//particleSystem.enabled = false;
fireIsOff = true;
flame.active = false;
yield WaitForSeconds(3);
}
}