Question by
INKnightStudio · Apr 10, 2017 at 03:34 PM ·
texttextfield
How do I make my script generate text in an InputField?
I have a code that can generate a code in a Text.UI, but it does not generate that code in texts with InputField.
public InputField input;
public Text resultMarkupFormat;
public Toggle bold;
public Toggle italic;
public Dropdown colorList;
string[] boldFormat = new string[2] { "<b>", "</b>" };
string[] italicFormat = new string[2] { "<i>", "</i>" };
string[] hexadecimal = new string[31]
{
"No Color",
"<color=#ff0000>Red</color> :#ff0000",
"<color=#ffe100>Yellow</color> :#ffe100",
"<color=#ff6600>Orange</color> :#ff6600",
"<color=#77c2ff>OrangeRed</color> :#77c2ff",
"<color=#ccff00>Lime</color> :#ccff00",
"<color=#00ff00>Green</color> :#00ff00",
"<color=#62ffab>Teal</color> :#62ffab",
"<color=#00ffff>Cyan</color> :#00ffff",
"<color=#1e90ff>Dodger Blue</color> :#1e90ff",
"<color=#0000ff>Blue</color> :#0000ff",
"<color=#5a00ff>Blue Violet</color> :#5a00ff",
"<color=#9800ff>Violet</color> :#9800ff",
"<color=#ff00ff>Pink</color> :#ff00ff",
"<color=#ff0084>Deep Pink</color> :#ff0084",
"<color=#ff7777>Light Red</color> :#ff7777",
"<color=#ffce81>Light Orange</color> :#ff9c70",
"<color=#ffef81>Light Yellow</color> :#fff070",
"<color=#ffef81>Light Lime</color> :#e3ff62",
"<color=#77ff79>Light Green</color> :#77ff79",
"<color=#81ffb6>Light Teal</color> :#81ffb6",
"<color=#adfcff>Light Cyan</color> :#adfcff",
"<color=#87c8ff>Light Dodger Blue</color> :#87c8ff",
"<color=#77c2ff>Light Blue</color> :#77c2ff",
"<color=#a087ff>Light BlueViolet</color> :#a087ff",
"<color=#bd87ff>Light Violet</color> :#bd87ff",
"<color=#f287ff>Light Pink</color> :#f287ff",
"<color=#ff78d1>Light Deep Pink</color> :#ff78d1",
"<color=#FFFFFF>White</color> :#FFFFFF",
"<color=#969696>Gray</color> :#969696",
"<color=#000000>Black</color> :#000000",
};
void Start()
{
colorList.ClearOptions();
for (int i = 0; i < hexadecimal.Length; i++)
{
string[] hexa = hexadecimal[i].Split(':');
Dropdown.OptionData data = new Dropdown.OptionData();
data.text = hexa[0];
colorList.options.Add(data);
}
}
void Update()
{
resultMarkupFormat.text = VerifyResult();
}
string VerifyResult()
{
string[] markup = new string[2] { "", "" };
if (input.text.Length > 0)
{
markup[0] = bold.isOn ? boldFormat[0] : "";
markup[0] += italic.isOn ? italicFormat[0] : "";
if (colorList.value > 0)
{
string[] hexa = hexadecimal[colorList.value].Split(':');
markup[0] += "<color=" + hexa[1] + ">";
}
markup[1] = bold.isOn ? boldFormat[1] : "";
markup[1] += italic.isOn ? italicFormat[1] : "";
if (colorList.value > 0)
markup[1] += "</color>";
}
return markup[0] + input.text + markup[1];
}
}
Comment
Best Answer
Answer by Cuttlas-U · Apr 10, 2017 at 04:52 PM
Hi;
the InputFiled component has a text variable ; try to change the value of that and i think u are good to go ;
GetComponent<InputField>().text = "your text";
terrain-to-mesh-v143.png
(48.5 kB)
Your answer
Follow this Question
Related Questions
I'm trying to insert input field text into an arraylist 0 Answers
Working with the GUI 4.6 (textfields and buttons) 1 Answer
TextField does not update in Game 1 Answer
Text Boxes Not Visible 0 Answers
Can't put a text on an Object 0 Answers