Hello,
I’ve been playing with enabling and disabling a particle system by the holding or release of a button press. I have a question.
Question:
Is there a more elegant/efficient way to enable and disable a particle system than this?
/*************************************************************************************************
* Important Note
* The emission module is "emission" category on the Particle System component
* We are checking the boolean true/false to turn this on and off
* In play mode you can watch the checkbox by emission come on and off as you press "Jump"
*************************************************************************************************/
private ParticleSystem ps; // Variable to refer to your particle system
void Start()
{
ps = GetComponent<ParticleSystem>(); // Get the particle system on your GameObject once
var emission = ps.emission; // Get the current emission module
Debug.Log(emission.GetType().FullName);
emission.enabled = false; // Set the emission module to disabled at start
}
void Update()
{
if (Input.GetButtonDown("Jump")){ // The one frame when you press the jump key, turn it on
var emission = ps.emission; // Get the current emission module
emission.enabled = true; // Set the emission module to enabled
}
if (Input.GetButtonUp("Jump")){ // The one frame when you let go of the jump key, turn it off
var emission = ps.emission; // Get the current emission module
emission.enabled = false; // Set the emission module to disabled
}
}
- I want to create the emission variable globally for access in all the methods (Start/Update) for future use rather than using “var emission = ps.emission” every time I want to enable/disable.
- There doesn’t seem to be a class/dataType that I can use though. The data type that typeOf() returns is ParticleSystem+emissionModule
Thank you,
Brendan