i’ve a couple of gameobjects to instantiate with dragmouse script.i instantiate a few gameobjects.then ive a toggle for enableing that dragmouse script of instantiated.but its not working properly.
Now my question is how can i disable or enable that script of instantiated with toggle.how can i use find()? how can i achieve it please help me out.
Can you pls explain that How/Which gameObject’s script you want to disable … ( i.e. How you can decide that now this or that one gameObject should disable the ‘dragmouse’ script).
If you need the last one then the following code can work
currentLoadedModel = Instantiate (objTemp) as GameObject;
currentLoadedModel.GetComponent<dragmouse>().enabled = false;
I’m not sure I understand your question, but just in case:
GetComponent<YourScriptName>().enable = true/false
allows you to enable / disable a component.
- Get its component.
Instantiate( yourGameObject).GetComponent().enabled = false;
Thanks everyone. Actually my need is i’ll instantiate gameobjects which have dragmouse script but initially that script is disabled by manually.next ive a toggle for enable that script…i tried all what you have mentioned in answers.But here is i’ve a script for instantiating objects like cube,sphere. and in another script one toggle is there. if it is true script will enable and i’ll change the position of particular gameobject with mouse.but it is working sometime but its not disabling all time. i added tag “Drag” for all my gameobjects which are going to instantiate.
so i want all gameobjects who have drag tag. then i’ll use getcomponent().enabled=false/true. i tried with GameObject.FindWithTag. but i’m getting only first object. a want all in on array.
Again Thanks for your effort.
i got my solution finally. thanks guys for your support. i’m unable to post this as answer.tell me how to do this question as solved. here is the code.
for(int i =0;i().enabled=false;//or true.