Skip to main content
18 events
when toggle format what by license comment
May 15, 2013 at 15:04 vote accept Anton Garcia Dosil
May 15, 2013 at 7:53 answer added tbkn23 timeline score: 0
May 14, 2013 at 15:50 comment added Benjamin Danger Johnson I'm a bit confused. Generally speaking, a script is a C# class that extends MonoBehaviour. Now not all scripts extend Monobehaviour, that is just a requirement if you want to attach the script to a GameObject. Anyway so there are two things I think you are asking, the first was how to get components and I mentioned "GetComponents<MonoBehaviour>()" already, the second is how to add a script at runtime which is something like "ScriptClassName script = gameObjectVariable.AddComponent(typeof (ScriptClassName)) as ScriptClassName;"
May 14, 2013 at 14:19 comment added Tetrad I don't think it's possible to do what you want to do at runtime. I'm assuming you want to set the script on the mono behavior to preserve serialized data. If not you could just add the component and call it a day.
May 14, 2013 at 10:32 comment added Anton Garcia Dosil @Tetrad I want to define the existing components not to add new ones. I have edited the description to see if its clearer.
May 14, 2013 at 10:30 history edited Anton Garcia Dosil CC BY-SA 3.0
added 191 characters in body
May 14, 2013 at 10:26 comment added Anton Garcia Dosil @Tetrad I need to attach the script I made for the prefab to the existing Monobehaviour component, not to a new one. The idea is to assign my scripts to the monobehaviour components (To the missing mono script parts).
May 14, 2013 at 10:23 comment added Tetrad When you say "attach the scripts" do you mean you need to assign a variable to a script you made or do you mean you need to attach the script you made to the prefab itself? For the former you need to get the specific derived type so you can access the variable. For the latter you want to AddComponent instead and what you're asking doesn't make any sense. What does the prefab look like in the inspector?
May 14, 2013 at 9:54 comment added Anton Garcia Dosil @BenjaminDangerJohnson I need to attach the scripts to those Monobehaviour components
May 14, 2013 at 9:52 comment added Anton Garcia Dosil @Tetrad Using only GetComponent I get a null object
May 14, 2013 at 9:40 history edited Anton Garcia Dosil CC BY-SA 3.0
added 105 characters in body
May 14, 2013 at 9:26 history edited Anton Garcia Dosil CC BY-SA 3.0
added 164 characters in body
May 13, 2013 at 22:27 comment added Tetrad If you try it with GetComponent do you get a single component back? Why are you using the base class MonoBehaviour instead of something you implemented?
May 13, 2013 at 21:19 comment added Benjamin Danger Johnson Normally people would get the components like this "Kinect_Prefab.GetComponents<MonoBehaviour>();" but unless you are receiving a compilation error I doubt that is your problem. Could the scripts you are looking for be attached to children of the prefab?
S May 13, 2013 at 21:14 history suggested Doorknob CC BY-SA 3.0
code formatting, general cleanup
May 13, 2013 at 21:01 review Suggested edits
S May 13, 2013 at 21:14
May 13, 2013 at 20:50 review First posts
May 13, 2013 at 21:01
May 13, 2013 at 20:32 history asked Anton Garcia Dosil CC BY-SA 3.0