- Home /
Adding in other variables through the inspector in a public string
I have a public string defined in a script that I am attaching to a few different game objects in a scene, so I can just fill in that string in the inspector for each of these objects. It's a string that will write to a text object, and this is all fine.
However, I want to be able to add some string variables to this string in the inspector, like:
"Hi, my name is " + _name + " , nice to meet you";
This is all well and good when written in the script, but attempting to do this through the inspector just includes all the quotation marks, etc.
I'm guessing that strings entered through the inspector automatically add the quotation marks to anything entered in the field. Is there some way to null that so I can cobble together this string with variables in the inspector? Many thanks!
Answer by etopsirhc · Sep 12, 2016 at 06:13 AM
you'll need to make a "tag" of some sort, like &name then use Replace() on the string. so
public string inspectorString = "Dang it &name!";
void Start(){
inspectorString.Replace("&name","Bobby");
}
Your answer
Follow this Question
Related Questions
is there a way to minimize amount of public items in inspector? 1 Answer
Cannot assign Public GameObject variable in Inspector... 2 Answers
Some Public Variables doesn't display in Inspector 2 Answers
GUIText new line through inspector 1 Answer
Can you make changes to exposed public variables persist in inspector ? 1 Answer