- Home /
This question was
closed Oct 23, 2013 at 02:34 AM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Question by
R1pnd1p · Oct 18, 2013 at 02:43 AM ·
particlesystemrendererdisableenable
am i doing this right? (renderer enable/disable)
using UnityEngine;
using System.Collections;
public class flamebreath : MonoBehaviour {
// Use this for initialization
void Start () {
particleSystem.renderer.enabled = false;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.F)){
particleSystem.renderer.enabled = true;
}
if (Input.GetKeyDown (KeyCode.F)){
particleSystem.renderer.enabled = false;
}
}
}
when i press play, the renderer on the particle effect is off, but when i press "F" it doesent turn on.
i removed the line of code in "start" and yes, the fire does spawn, but when i press "F" it disables and doesent turn back on. thanks in advanced!
Comment
Best Answer
Answer by LukaKotar · Oct 18, 2013 at 02:47 AM
You are setting it to true, then back to false. Both if
statements will execute.
if (Input.GetKeyDown (KeyCode.F)){
//The line below will set enabled to the opposite value:
particleSystem.renderer.enabled = !particleSystem.renderer.enabled;
}
void Start () {
particleSystem.renderer.enabled = !particleSystem.renderer.enabled;
}
// Update is called once per frame
void Update () {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.F)){
particleSystem.renderer.enabled = true;
}
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.F)){
particleSystem.renderer.enabled = !particleSystem.renderer.enabled;
}
}
}
this is the changes i made, its still not enabling the renderer, it stays off.
Delete the first if
statement.
This should work:
void Start () {
particleSystem.renderer.enabled = false;
}
void Update () {
if (Input.GetButtonDown ($$anonymous$$eyCode.F)){
particleSystem.renderer.enabled = !particleSystem.renderer.enabled;
}
}