2016年11月10日 星期四

uiity版剪刀石頭布





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 ()
{
        int d = Random.Range(1, 4);
        Text mytxt = GameObject.Find ("Canvas/Panel/Text").GetComponent<Text>();
mytxt.text = d.ToString ();
       
        Image Img = GameObject.Find("Canvas/Panel/Image").GetComponent<Image>();
        if (d == 1)
            {
               
                Img.sprite = Resources.Load<Sprite>("Image/a") as Sprite;
            }

            if (d == 2)
            {
               
                Img.sprite = Resources.Load<Sprite>("Image/b") as Sprite;
            }

            if (d == 3)
            {
               
                Img.sprite = Resources.Load<Sprite>("Image/c") as Sprite;
           
        }
    }

}

沒有留言:

張貼留言