0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unity > uGUI > Text > Textに文字を書く

Last updated at Posted at 2015-08-13
動作確認
Unity 5.1.1-f on Mac OS X 10.8.5

UI > Textに文字列を書くには。

  1. using UnityEngine.UI; を追加
  2. public Text ResultText; にて ResultTextにUI > Textを関連づける。
  3. ResultText.text = "this is result"; のようにする。
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // for Text

public class MyButton : MonoBehaviour {
	public Text ResultText;

	void Judge(bool isHigh) {
		int num = Random.Range (0, 13); // integer random number
		Debug.Log (num.ToString ());

		if (isHigh) {
			ResultText.text = "High";
		} else {
			ResultText.text = "Low";
		}
	}

	public void ButtonClick() {
		switch (transform.name) {
		case "ButtonHigh":
			Judge(/* isHigh=*/ true);
			break;
		case "ButtonLow":
			Judge(/* isHigh=*/ false);
			break;
		default:
			break;
		}
	}
}
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?