Search code examples
c#unity-game-enginengui

Cannot implicitly convert type 'string' to 'UIInput'


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;

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.