conf t

インフラエンジニアのメモ

UnityでGetComponent<Text>()でのエラー

UnityでGetComponent()でテキストを取得して、 uGUIのTextのテキストを変更したい時。

GameObject.Find ("ScoreText").GetComponent<Text>().text = "aaa"

以下のエラーに良く遭遇する。

The type or namespace name `Text' could not be found. Are you missing a using directive or an assembly reference?

上記エラーの場合は、ちゃんとusingをしているかを確認する。

using UnityEngine.UI;

久しぶりにUnityいじると、よく上記のエラーに遭遇し、あれスペルミスかな?用法が違う?でも間違っていないぞ?
といつも時間を無駄にしてしまう。