Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Getting Gameobject from OnValueChanged

Discussion in 'Scripting' started by RPGFabi, Jan 9, 2020.

  1. RPGFabi

    RPGFabi

    Joined:
    Oct 24, 2019
    Posts:
    29
    Hey,

    currently trying to get the Gameobject of the InputField which calls OnValueChanged().

    Code (CSharp):
    1. public void ChangeToUpper(string key)
    2.         {
    3.            
    4.             if(key.ToUpper() != key)
    5.             {
    6.                 Debug.Log("NOW! Oldkey: " +key+ " ; Newkey:"+key.ToUpper());
    7.                 gameObject.GetComponent<InputField>().SetTextWithoutNotify(key.ToUpper());
    8.             }
    9.         }
    The Debug.Log is called correctly so the error is in the
    gameObject.GetComponent<InputField>().SetTextWithoutNotify(key.ToUpper());


    The Script is attached to an Empty Gameobject (my Manager). Now this Manager is in the OnValueChanged() calling this function.

    How can i Get the Gameobject which is calling the OnValueChanged() (here the InputField)??
     
  2. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    210
    You will have to attach this script to the GameObject that also has the InputField. OnValueChanged only has a string parameter, so there is no way to find out the source from that.
     
  3. RPGFabi

    RPGFabi

    Joined:
    Oct 24, 2019
    Posts:
    29
    Done. Thx works fine