- Home /
Add a new script line to my script with text from textboxes after button in the Inspector is pressed
Hello Unity community.
I would like to know how I can add a new line of code (at a specific line (for example line 48)) which is already pre-written but only get pasted at line 48 after a Inspector button was pressed. The pre-written code has some variables in it and these variables should be replaced with the entered text of the textboxes when the pre-written code was posted.
If you don't understood what I said I will show you an example:
void LoadFeatures()
{
features = new List<Feature>();
public TextBoxA = textbox1; //something like this?
..........
//features.Add(new Feature("Name of file in Textures folder", transform.FindChild("Name of the child in Hierarchy".GetComponent<SpriteRenderer>()));
features.Add(new Feature("TextBoxA", transform.FindChild("TextBoxB").FindChild("TextBoxC").GetComponent<SpriteRenderer>()));
}
So, this is the code. Off topic: LoadFeatures does mean that the Unity Editor have to load everything which was selected in a previous play time after the play button was pressed!
My Example:
In the Inspector of Unity I have three textboxes and one button (in my added script to an empty GameObject). What I want is that after the button was pressed the pre-written code -> features.Add(new Feature("TextBoxA", transform.FindChild("TextBoxB").FindChild("TextBoxC").GetComponent()));
shall be added to line 48 in the script and the variables TextBoxA, TextBoxB & TextBoxC shall be replaced with the Text I entered in the three Inspector textboxes before. I think this is something like a 'on click' event.
Does anyone know how to do something like this? Because I have the idea but don't know exactly how to solve it.:/
Your answer
Follow this Question
Related Questions
Select monobehaviour function from inspector 1 Answer
Alerts 3D game mobile controls with UI 0 Answers