Question

I have problem converting type String to UI Input in Unity3D. I want to retrieve the information from database and place them in a textbox (UI Input)

This is the error message. (1st error)

"Cannot convert method group ToString' to non-delegate typeUIInput'. Consider using parentheses to invoke the method"

password = GameObject.Find ("tb_password").GetComponent <UIInput> ().ToString;
Was it helpful?

Solution

You are trying to override the label with a string value, which results in type mismatch and actually is not what you've intended. You have to access UIInput property value or defaultValue if you wan't to provide defaults for user - anyway according to your code you probably don't want it.

Anyway, if you are using the latest NGUI, you should correct your code like this:

UIInput username = GameObject.Find ("tb_username").GetComponent <UIInput> ();
UIInput password = GameObject.Find ("tb_password").GetComponent <UIInput> ();

if( username != null )
    username.value = DB.getName(LoginSystem.userNameStatic);
if( password != null )
    password.value = DB.getPassword ("password");

That should work if you correctly find objects with these names you specify, otherwise it won't do anything.

OTHER TIPS

You could access the UILabel component under the NGUI's input widget instead of the UIInput component at the root of the input widget and set the text in the label (UILabel.text = "my text"). You could also make a function that updates the label text and pass the text as a parameter for this function. Call the function when you want to update the text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top