- Home /
Question by
louisafilary · Jan 23, 2017 at 12:53 PM ·
javascriptparticle systemnoobemissionparticleemitter
Can't get particles to enable/disable with button press
I downloaded a basic campfire asset that has light and particle systems to make up the fire, and I want to have the player walk up a press "5" to light the fire. I can get the light element to work but not the empty gameobjects with particle systems!! this is my code (spark, light, and flame are all particle system based):
var fireLight : GameObject;
var fireSpark : GameObject;
var fireHeat : GameObject;
var fireFlame : GameObject;
function Start() {
fireLight.SetActive(false);
fireSpark.gameObject.GetComponent<ParticleSystem>().enableEmission = false;
fireHeat.gameObject.GetComponent<ParticleSystem>().enableEmission = false;
fireFlame.gameObject.GetComponent<ParticleSystem>().enableEmission = false;
}
function Update() {
if(Input.GetKeyDown("5"))
fireLight.SetActive(true);
fireSpark.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
fireHeat.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
fireFlame.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
}
Comment
Have you attempted to change the code in Update from
function Update(){
if(Input.Get$$anonymous$$eyDown("5"))
fireLight.SetActive(true);
fireSpark.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
fireHeat.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
fireFlame.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
}
}
To ?
function Update() {
if(Input.Get$$anonymous$$eyDown("5"))
{
fireLight.SetActive(true);
fireSpark.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
fireHeat.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
fireFlame.gameObject.GetComponent<ParticleSystem>().enableEmission = true;
}
}