Hi Unity community!
I am using the UI InputField gameobject and am able to retrieve its string value easily via the Text.text component.
However I can’t seem to update the component’s string value using the same method (I want the error report to be assigned to the Input Field’s displayed text). The function reports the Debug error fine so I assume it is the way I am assigning the new string.
Can someone explain to me why this is incorrect? I have searched all over to no avail.
Many thank in advance!
Ryan
public function ObjNameEd(){ //function for editing the name of gameobject via GUI
var curObj : GameObject = GameObject.FindGameObjectWithTag("Current Model");
var userField = GameObject.Find("ObjectNameFieldText").GetComponent(Text);
if(curObj != null){
if(userField.text.Length > 5 ){ //Correct Input
var newObjName : String = userField.text;
curObj.name = newObjName;
} else if (userField.text.Length < 5){ //Incorrect Input: Error
var errorRep : String = "Must be 5+ chars";
userField.text = errorRep;
Debug.Log("Must be 5+ chars");
}
} else {
Debug.Log("No model uploaded");
}
}