動作確認
Unity 5.1.1-f on Mac OS X 10.8.5
UI > Textに文字列を書くには。
- using UnityEngine.UI; を追加
- public Text ResultText; にて ResultTextにUI > Textを関連づける。
- 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;
}
}
}