Skip to content

Accessing Scripts

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… Read More »How to Access a Clone or Clones of a Prefab and Reference Its Script or Other Component in Unity

How to Access Another Script in Unity using C#

Accessing a script in a gameobject from another script in another gameobject public class Object1Script: MonoBehaviour {      public GameObject object2WithScriptToAccess;      public NameOfScriptToAccess nameOfScriptToAccessScript;   void Start()      {           nameOfScriptToAccessScript = object2WithScriptToAccess.GetComponent();      }   void Update ()… Read More »How to Access Another Script in Unity using C#