How to disable a script on a bunch of instantiated objects with tag ?

Ok I have enemyManger which instantiate a prefab that has a movement script attached to it . I created a tag so i can collect them later . now I do want to have a freeze bomb which disable their movement for a while but it seems not to work

   IEnumerator Enemyfreezer()
    {
        yield return new WaitForSeconds(1f);
        GameObject[] gameObjectArray = GameObject.FindGameObjectsWithTag("Zombie");
        foreach (GameObject go in gameObjectArray)
        {
            go.GetComponent<EnemyMovement>().enabled = false;
        }
        yield return new WaitForSeconds(3f);
        GameObject[] gameObjectArray1 = GameObject.FindGameObjectsWithTag("Zombie");
        foreach (GameObject go in gameObjectArray1)
        {
            go.GetComponent<EnemyMovement>().enabled = true;
        }
    }

But when I replace the EnemyMovement with other component rather than a scripts it works just fine . like Animator component :

   IEnumerator Enemyfreezer()
    {
        yield return new WaitForSeconds(1f);
        GameObject[] gameObjectArray = GameObject.FindGameObjectsWithTag("Zombie");
        foreach (GameObject go in gameObjectArray)
        {
            go.GetComponent<Animator>().enabled = false;
        }
        yield return new WaitForSeconds(3f);
        GameObject[] gameObjectArray1 = GameObject.FindGameObjectsWithTag("Zombie");
        foreach (GameObject go in gameObjectArray1)
        {
            go.GetComponent<Animator>().enabled = true;
        }
    }

Help Please :smiley:

Setting enabled to false, only make Update functions to stop. If you’re using coroutines to move your enemy, or as @fafase told in comments, another scripts make the enemy move, then it won’t work. I suggest you add Stop() and Resume() methods to your enemy class. When you call Stop() method, not only it will set enabled to false and stop all coroutines, it will also raise a flag (_movability = false) so the enemy refuses to move afterwards. Even if other components told it so. I think it will solve your problem.