Particle System is not playing through code

I’m using this method and tried some others as well but unable to play the particle system(i.e for bullet shells .

             ParticleSystem particleSystem; 
              private bool isPlaying = false;

        void Start () {
       particleSystem = GetComponent<ParticleSystem>();
     particleSystem.Clear(); // Reset the particles
      }

              Update is called once per frame
                    void Update () {
            if(!particleSystem.isPlaying) particleSystem.Play();

             if(!isPlaying) {
            particleSystem.Play();
     isPlaying = true;
         }

okay so after trouble of hours i found that the best way to manipulate the particle system i.e activate and detivate on your will is to create an empty gameobject assign the particle system you made to it and then on and off this gameobject exactly at which part in the code you want to by setActivce command. I hope it will someone in someway