Javascript: Appearing and Disappearing objects
Hi! So I want to make a fire that starts when I use a box of matches on it... I have a script that allows me to pick up my "matches" and then the fireplace is supposed to display a message, and when "E" is clicked, the fire is supposed to appear. Here is my script:
#pragma strict
var buttonInRange;
var buttonActivated;
var batterySound : AudioClip;
private static var batteryPower : float = 10;
var Matches : GameObject;
var Fire : GameObject;
private var hasPlayed = false;
Fire.SetActive(false);
function Start()
{
}
function OnTriggerEnter (c : Collider)
{
buttonInRange = true;
}
function OnTriggerExit (c : Collider)
{
buttonInRange = false;
}
function OnGUI ()
{
if (buttonInRange == true)
{
if (Matches == false)
{
Fire.SetActive(true);
GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50), "Use matches");
}
}
}
function Update ()
{
if (buttonInRange == true)
{
if (Input.GetKeyDown ("e"))
{
if(!hasPlayed)
{
AudioSource.PlayClipAtPoint(batterySound, transform.position);
Fire.SetActive(true);
hasPlayed = true;
}
}
}
}
However, because I set the Fire.Active to false, it doesn't play the function Update() part.... Is there an alternative way to do this? All answers are greatly appreciated... Thanks :D
Your answer
Follow this Question
Related Questions
Make object active only once 0 Answers
How to add a script to a parent object and not every individual child object. 1 Answer
Cannot convert void to UnityEngine.UI.Toggle.ToggleEvent - Javascript 0 Answers
Object Appear When Hit Terrain And Then Place it 0 Answers
Target appearing and disappearing 0 Answers