- Home /
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 $$anonymous$$eshRenderer of the instantiated gameobject.
Hope it solves your problem..let me know if there's any other issue ..
Answer by aman_jha · Sep 08, 2014 at 04:39 PM
GameObject gameThingy = Instantiate(objectToClone, Vector3.zero, Quaternion.identity) as GameObject;
gameThingy.GetComponent<it>().enabled = false;
Your answer
Follow this Question
Related Questions
GetComponent of ALL clones? 2 Answers
Assign an instantiated GameObject? 1 Answer
How to attach a prefab to a script that is added dynamically 0 Answers
Deleting a GameObject 2 Answers
Instantiated Object turning off scripts and audio source?(Solved) 1 Answer