0

I'm trying to make a chat box appear with a simple function, so I'm adding all the fields in the background - back panel, top bar, messages, and that's all working well enough.

I'm now trying to add an InputField in much the same way as the others, and running into problems.

Here's what I have so far:

 private InputField nameInputField;
 string placeHolderText = "";

and then

 nameInputField = new InputField ();
 placeHolderText = nameInputField.placeholder.GetComponent<Text> ().text = "type something here";

I'm getting an error on nameInputField = new InputField (); , and not sure why.

Further, I'd like to be able to manipulate the location and dimensions of the InputField, along with the font and other formatting issues.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Steven Jacks
  • 313
  • 1
  • 2
  • 14
  • `InputField` is a component. `AddComponent` should be used instead of the `new` keyword but the duplicate shows a better way to create UI controls from script. – Programmer Sep 29 '17 at 09:50
  • Also, I generally like creating prefabs for something like this as often times I'll want more than just a new component. Many of the new UI objects are made of up three or for actual objects (scroll rects are made of 8 game objects, with about one component each!) – Draco18s no longer trusts SE Sep 29 '17 at 15:59

0 Answers0