title: Add particles on button click in unity
body: <p>I am new to unity 3d, I have to do some enhancement in exiting project.. if user choose correct option then I have to show some particles around the button at runtime.
  My code for adding particles is below ..not working:</p>
  
  <pre><code>ParticleSystem ps = GetComponent&lt;ParticleSystem&gt;();
  ps.Play ();
  </code></pre>
  
  <p>I have also added particles component from unity editor..</p>
  
  <p>Thanks in advance</p>
  
  <p>Edit :</p>
  
  <p>as @kardux suggested:</p>
  
  <p>declaration :</p>
  
  <pre><code>[SerializeField] private ParticleSystem ps;
  </code></pre>
  
  <p>on method :</p>
  
  <pre><code>ps.Play()
  </code></pre>
  
  <p>Screenshot from inspector:</p>
  
  <p><a href="https://i.stack.imgur.com/fwl3A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fwl3A.png" alt="enter image description here"></a></p>
  
  <p>Error:</p>
  
  <pre><code>I/Unity   (23313): NullReferenceException
  I/Unity   (23313):   at UnityEngine.ParticleSystem.&lt;Play&gt;m__0 (UnityEngine.ParticleSystem ps) [0x00001] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3666 
  I/Unity   (23313):   at UnityEngine.ParticleSystem.IterateParticleSystems (Boolean recurse, UnityEngine.IteratorDelegate func) [0x00003] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3780 
  I/Unity   (23313):   at UnityEngine.ParticleSystem.Play (Boolean withChildren) [0x00020] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3666 
  I/Unity   (23313):   at UnityEngine.ParticleSystem.Play () [0x00005] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3661 
  </code></pre>