Search Unity

Updating input field with code without having to click on it first

Discussion in 'Scripting' started by JACKO4590, May 24, 2020.

  1. JACKO4590

    JACKO4590

    Joined:
    Nov 25, 2014
    Posts:
    81
    OK I have made a simple script to handle changing the input fields content type from password to standard.
    While observing the inspector its changing it straight away like its meant too but its not updating the text field on screen. Not until its clicked on.

    Code (CSharp):
    1. public void ShowPassword1() {
    2.         if (newPassword.contentType == InputField.ContentType.Standard) {
    3.             newPassword.contentType = InputField.ContentType.Password;
    4.         }
    5.         else if (newPassword.contentType == InputField.ContentType.Password) {
    6.             newPassword.contentType = InputField.ContentType.Standard;
    Is there anything I can do to get this text field to update right away or am I out of luck?
    Thanks~
     
  2. JACKO4590

    JACKO4590

    Joined:
    Nov 25, 2014
    Posts:
    81
    Ok I feel dumb. I got it sorted now. Feel free to tell me if this isnt the right way but when I pass through the change of content type I'm also turning off the text gameObject and turning it on again and now its updating right away,