Skip to content

How to Access a Clone or Clones of a Prefab and Reference Its Script or Other Component in Unity

Ex. 1

var prefabClones = GameObject.FindGameObjectsWithTag(“Tag”);

        foreach (var prefabClone in prefabClones)

        {

            Destroy(prefabClone);

        }

Ex. 2

var prefabClones = GameObject.FindGameObjectsWithTag(“Tag”);

        foreach (var prefabClone in prefabClones)

        {

prefabClone.gameObject.GetComponent<NameOfScript>().enabled = false;

        }

Ex. 3

var prefabClone = GameObject.FindWithTag(“Tag”);

       {

          Destroy(prefabClone);

       }

Leave a Reply

Your email address will not be published.