Search Unity

Question Acces InputField from Script

Discussion in 'UGUI & TextMesh Pro' started by Thomas_DK, Sep 14, 2022.

  1. Thomas_DK

    Thomas_DK

    Joined:
    Feb 1, 2018
    Posts:
    3
    Hi there,
    I am trying to acces the text from an InputField which is a child.
    --- Hirachy --------
    - InputCanvas
    -- Image <Image>
    -- MathInput <InputField>
    -- Math <Text>
    ----------------------

    I can acces the Math<Text> Propertie with the following:
    Code (CSharp):
    1.  
    2. GameObject InputCanvas;
    3. InputCanvas = GameObject.Find("InputCanvas");
    4.  
    5. Transform textTr = InputCanvas.transform.Find("Math");
    6. Text mathText = textTr.GetComponent<Text>();
    7. mathText.text = "This is my Text";
    8.  
    But so far I have had no luck accesing the text which is in the InputFields Text property.

    Any Help would be greatly appriciated!

    Best wishes
    /Thomas