- Home /
turning on a particle with an input key
hey there, i have this code on my waterfall, i need to turn it on with my input key "o" but when i test it out it says
Your script should either check if it is null or you should not destroy the object. heres my code using UnityEngine; using System.Collections;The object of type 'ParticleEmitter' has been destroyed but you are still trying to access it.
public class sensorwaterfall : MonoBehaviour {
public ParticleEmitter myBigmist = null; public ParticleEmitter myBigfoam = null; public ParticleEmitter myBigsplash = null;
// Use this for initialization void Start () { myBigmist.emit = false ; myBigfoam.emit = false ; myBigsplash.emit = false ; }
// Update is called once per frame void Update () { if (Input.GetKeyDown("o")){ myBigmist.emit = true ; myBigfoam.emit = true ; myBigsplash.emit = true ;
}
} } i have manually dragged the components to the = null in my inspector thanks ![alt text][1] ![alt text][2] [1]: /storage/temp/1816-emitter+1.jpg [2]: /storage/temp/1817-emitter+2.jpg
hmm what are you attaching in inspector, prefab or a gameobject from scene?!
is there something that destroys your particle emitter, because according to the error the particle emitter was there but was destroyed.
@Flamy; im attaching a particle prefab from the scene
@TheDarkVoid; this is the issue, I havent destroyed it, im simply trying to say, untill "o" is pressed, the emitters should be false, when "o" is pressed, the emitters should be true
im not getting again... is it in scene or project? if it is in project what ever you are trying wont work..
The code is perfect. Just make sure that the prefab is in the scene not just in the project.
here is a screen of what I have set up, the prefab is a waterfall prefab with the emitters within it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074039im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
All instances of particle emitter prefab are emitting when emit=true 0 Answers