Django Girls and Boys 備忘録

Python、Selenium、Django、java、iPhoneアプリ、Excelマクロなどで気付いたこと、覚えておきたいことなどを載せていきます。

【Unity】The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)に遭遇した時の対処方法

 

Unityで開発中にGetComponent()でテキストを取得して、 uGUIのTextのテキストを操作しようとする場合などに以下のようなエラーに遭遇します。

 

 

 

1.エラーとコード例

 

エラーに遭遇する時のコード例

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

 

遭遇するエラー

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

 

2.解決方法

 

はじめはどこが悪いのかすぐには分からなかったりしますが、結果的には以下をusingしているかを確認し、ない場合にはusingの追加で解決します。

 

確認するコード

using UnityEngine.UI;