using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
public Text mytext;
public Button B;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void myfun()
{
Text mytxt = GameObject.Find ("Canvas/Panel/Text").GetComponent<Text>();
mytxt.text =Random.Range(1,4).ToString();
}
}
隨機亂數+圖像
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void myfun()
{
Text mytxt = GameObject.Find ("Canvas/Panel/Text").GetComponent<Text>();
int c = Random.Range (1, 4);
mytxt.text =c.ToString();
Image Imgy = GameObject.Find ("Canvas/Panel/Image").GetComponent<Image>();
if (c == 1) {
Imgy.sprite = Resources.Load<Sprite> ("Image/E") as Sprite;
}
if (c == 2) {
Imgy.sprite = Resources.Load<Sprite> ("Image/D") as Sprite;
}
if (c == 3) {
Imgy.sprite = Resources.Load<Sprite> ("Image/B") as Sprite;
}
}
}