Script variable

Hey,

I was wondering whether it is possible to create variable by script through the inspector.

So basically what I mean is that I want to create a game object in the inspector. And with that game object i want to automatically create a new variable in my script, which will have the name of my game object. So I don’t have to script the variable myself.

So is it possible to create script content through another script. like loading the an entire script as string, editing that string and then reusing that string as script. This would only have to work in Unity editor, not in-game.

Would be great if you could help me out with that.

The short answer is yes. Unity has a package on the asset store that does similar to what you are asking (and what Unity itself does when you create a new script). As I remember, a lot of the source is included so you can see how you could go about making what you suggested. I hope that helps =)

P.s. We use a similar method to create custom inspectors for our components by simply right clicking on them and selecting a custom context menu item. This creates an inspector script with our standard setup.