This is 'Input Field' component capture image.
Blue box is 'Placeholder' without linked. I want to set this value with my placeholder object
I mean 'my placeholder object' below.
In unity editor, I can set this using dragging 'my placeholder object' to blue box.
My question point is that how to get this via script.
InputField myInputField = myGameObject.AddComponent<InputField>();
myInputField.GetComponent<InputField>().placeholder = placeH01;
<< not working, type mismatch error with GameObject and UI.Graphic
CodePudding user response:
I don't see what placeH01
is in your code but it sounds like it is a GameObject
and you probably rather would want
// The GetComponent<InputField>() is quite redundant btw
// myInputField already IS an InputField
myInputField.placeholder = placeH01.GetComponent<UI.Graphic>();