Problem with Object Pooling and Deactivating Objects.!!

I’ve a top down shooter game where the player shoots continuous laser beam , I’ve achieved this with line renderer and raycast. Everything works well the laser shoots and collides with enemy. But i wanted to try some particle effect at the end of collision i’ve provided the hyper link to what i’m implying.
[link text][1]
[1]: https://img.itch.zone/aW1nLzE4NzQzMTAuZ2lm/original/fsRc9m.gif

At the collision i want the particle effect to play. So this is what i’ve did

 // Update is called once per frame
    void Update()
    {
        _lineRenderer.SetPosition(0, new Vector3(transform.position.x, transform.position.y, transform.position.z));
        RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), transform.up);
        if (hit.collider.tag == "Enemy")
        {
            _lineRenderer.SetPosition(1, new Vector3(hit.point.x, hit.point.y, transform.position.z));
            hit.collider.gameObject.GetComponent<Enemy>().Health -= 1;
            laserHitEffect = ObjectPooler.SharedInstance.GetPooledObject("LaserBeam");
            laserHitEffect.transform.position = hit.point;;
            laserHitEffect.SetActive(true);
            StartCoroutine(DeactivateLaser());
        }
        else
        {
            _lineRenderer.SetPosition(1, transform.up * 2000);
        }
    }

    private IEnumerator DeactivateLaser()
    {
        yield return new WaitForSeconds(0.1f);
        laserHitEffect.SetActive(false);
    }

Before using pool i just simply instantiated and destroyed the particle effect object and it worked well the particle effect played at the collision and destroyed in 0.1sec , but instantiating and destroying large number of object again and again is certainly not performance friendly. So i decided to use object pooling.

laserHitEffect = ObjectPooler.SharedInstance.GetPooledObject(“LaserBeam”);

Here in the inspector “LaserBeam” tagged object are pooled and expanded as per necessary in real time.
but my problem is when the laser hit the enemy collider the gameobject gets activated but the Coroutine doesn’t disable the gameobject leaving red trails behind which obviously looks ugly.
can someone help me with this, or else any other ideas to achieve the above effect is also welcome.

Hi, @Poi7ioN! You do not need to activate and deactivate effect each 0.1f. instead of it, activate it once when you hit, and then sync position with hit point. once your laser stop hit or “miss” target - deactivate effect.
pooling system is better for objects like bullets. but for lasers its not needed.

     void Awake()
     {
          laserHitEffect = Instantiate(hitEffectPrefab);
          laserHitEffect.SetActive(false);
     }

     void OnDisable()
     {
           if(lasetHitEffect.activeSelf)
                laserHitEffect.SetActive(false);
     }

  // Update is called once per frame
     void Update()
     {
         _lineRenderer.SetPosition(0, new Vector3(transform.position.x, transform.position.y, transform.position.z));
         RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), transform.up);
         if (hit.collider.tag == "Enemy")
         {
             _lineRenderer.SetPosition(1, new Vector3(hit.point.x, hit.point.y, transform.position.z));
             hit.collider.gameObject.GetComponent<Enemy>().Health -= 1;

             if(!laserHitEffect.activeSelf)//activate effect if not activated
                   laserHitEffect.SetActive(true);

             //and update effect position
             laserHitEffect.transform.position = hit.point;
             laserHitEffect.transform.rotation = _lineRenderer.transform.rotation; //your hit effect should be turned "back" in prefab, so when we sync this rotations, you will see effect direction
             //you can remove rotation sync if not needed
         }
         else
         {
             _lineRenderer.SetPosition(1, transform.up * 2000);
             if(laserHitEffect.activeSelf)//deactivate effect if we "missed"
                  laserHitEffect.SetActive(false);
         }
     }