LoginSignup
3
2

More than 5 years have passed since last update.

NGUIのラベルの取得方法

Last updated at Posted at 2014-07-25

NGUI(ver 3.6.8)のラベルをスクリプトから取得する方法

NGUIで作成したラベル名は「LabelTest」

間違え

Test.cs
// その1
UILabel LabelText = GameObject.Find("Label(LabelTest)").GetComponent<UILabel>();

// その2
UILabel LabelText = GameObject.Find("Label(LabelTest)").GetComponent();

正解

Test.cs
UILabel LabelText = GameObject.Find("LabelTest").GetComponent<UILabel> ();

Webで調べると間違えの方法で書かれているところもあったが
実装するとエラーがでるため、正解の方法で取得できた

ちなみに、ラベルを取得して、そのラベルのテキストを書き換える場合は下記。
(例えば、カウントさせる場合などで使用)

Test.cs
LabelText.text = ("Test");
3
2
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
3
2