- Home /
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.
Answer by Chris_Dlala · Oct 14, 2014 at 07:34 PM
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.
Your answer
Follow this Question
Related Questions
Declaring animations on a script in the editor 1 Answer
Class Reference in Editor not working 1 Answer
Variables not visible in editor but accessible from other scripts 2 Answers
Better way to call function from another script from editor script? 1 Answer
Can I write a script to rename objects as I create them? 1 Answer