How can I enable/disable a component of a Clone

So I am working on a game which spawns between 0 and 12 clones of a prefab, what I wanted to do at first was to enable the component on a set amount of those clones but I couldn’t figure out how to do that, what I am trying to do at the moment is enable that component if a condition is reached but if I use gameobject.GetComponent().enabled = true; it has no effect on the prefab and the component is still disabled.
If there is another way of going about this please let me know as I really need to get it working.

So here's a workaround ... You can easily filter your Instantiated gameobject(s) on the basis of tag and then change their components or else you can get all your gameobjects and then enable or disable their components like as: GameObject go = (GameObject)Instantiate (goPrefab, Vector3.zero, Quaternion.identity); go.GetComponent().enabled = false ; // This will disable MeshRenderer of the instantiated gameobject. Hope it solves your problem..let me know if there's any other issue ..

1 Answer

1

GameObject gameThingy = Instantiate(objectToClone, Vector3.zero, Quaternion.identity) as GameObject;

gameThingy.GetComponent<it>().enabled = false;