Trouble stopping particle emission in unity
<p>I am trying to only allow the particle system to emit particles when something is visible. The particle system knows when to start if a Boolean named <em>avail</em> is true. The code I thought would work for this is the following:</p>

<pre><code>     if (avail)
    {

        GetComponent&lt;MeshRenderer&gt;().enabled = true;
        GetComponent&lt;ParticleSystem&gt;().enableEmission = true;
        print("Mesh enabled");

    }
</code></pre>

<p>However, this failed. I also tried: </p>

<pre><code>     if (avail)
    {

        GetComponent&lt;MeshRenderer&gt;().enabled = true;
        GetComponent&lt;ParticleSystem&gt;().emission.enabled = true;
        print("Mesh enabled");

    }
</code></pre>

<p>However, this too failed. On every site I have searched in, these two "solutions" came up but they don't work for me. the first example said "this method of doing this is obsolete" and the second example says I can't set "emission.enabled" to a variable because it is a getter not a setter. Any help with figuring this out is extremely appreciated.</p>