- Home /
Enable/Disabling particleSystems in hierarchy
Note that this is my first real javascript Unity project so i want things to work properly and learn as much as I can in the process.
I am trying to automatically control particle systems in my hierarchy so that i do not need to configure each 'ship' individually.
I was experimenting around with 'GetComponentsInChildren' but have had no luck
the code is as follows (Paraphrased from the original code)
What happens is when the player presses the 'fly' key, the particle effect enables the particles, and disable them on release (and no particles at all if there is no fuel left in the ship)
var emitter : ParticleSystem;
emitter = gameObject.GetComponentsInChildren (particleSystem) as ParticleSystem;
function Update () {
if (Input.GetKey(moveUp) && fuelCount >0 && enableFuel == true){
rigidbody.AddRelativeForce(Vector3.up * moveSpeed);
fuelCount -= fuelConsumption;
emitter.Play();
}
else if (Input.GetKeyUp(moveUp)){
emitter.Stop();
}
I thank any repliers in advance :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613131617im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particle System (shuriken) with mesh particles, change color? 0 Answers
Particle Emitter crashing! 1 Answer
How do I make a gun? 1 Answer
ParticleSystem/MeshParticleEmitter Optimisation and Culling. 1 Answer
ellipsoidparticleemitter 1 Answer