- Home /
Find a script by name and add it to gameObject?
to make it simpler, i want users to be able to use one script, and that script loads a mouseOrbit onto the camera when a button is pressed, and unloads it when it's pressed again.
can i do "if button down, camera.main.AddComponent ("mouseOrbit");"
thankyou
sc : $$anonymous$$onobehaviour = mouseOrbit ;
go.AddComponent(sc.GetClass()); ?
Answer by Lucanio · Sep 02, 2014 at 09:05 AM
You don't need to do this. Instead, you could goahead and add the script to the camera and uncheck it. Then when your button is pressed, call mouseOrbit.enabled = true; You'll need to get a reference to the mouseOrbit script. You can do that by making it public and linking it in the editor, if there is a finite number of buttons. If they are spawned at runtime however, you would do mouseOrbit = Camera.main.GetComponent();
Your answer
![](https://koobas.hobune.stream/wayback/20220613162117im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Error BCE0077 1 Answer
Saving changes while playing... 1 Answer
Play sound on mouse enter 1 Answer