image

cs

GameObject.Find("FooText").GetComponent<Text>().text = x.ToString();

テキスト自体に一意な名前”FooText”を振ってある場合。

FindでGameObjectを取った後Textにキャストしようとしたがそれは勘違いで、そのGameObjectにComponentとしてTextが入っているので、それをGetComponentすればよい。

テキストを持っている親オブジェクトに名前がある場合 cs

GameObject.Find("Foo").GetComponentInChildren<Text>().text = x.ToString();