LoginSignup
0
0

Unityでタイマー作成時にテキストオブジェクトがnullのとき

Posted at

エラーメッセージ

NullReferenceException: Object reference not set to an instance of an object

問題の箇所

this.timerText.GetComponent<Text>().text =this.time.ToString("F1");

何がダメだったのか

アタッチしたオブジェクトがTextMeshProで作成したテキストなのに、取得するコンポーネントでを取得しようとしていた。

解決策

GetComponentで取得するものをからに変えてしまえば良い

this.timerText.GetComponent<TextMeshProUGUI>().text =this.time.ToString("F1");
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0