close

擷取.PNG

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();

            }

}

隨機亂數+圖像

擷取.PNG

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;
        }
            }

}

 

arrow
arrow
    全站熱搜

    E163687413 發表在 痞客邦 留言(0) 人氣()