第一次做這個的時候有點不熟悉
不管是語法還是UNITY
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()
{
int num = Random.Range(1,4);
Text mytxt = GameObject.Find ("Canvas/Panel/Text").GetComponent<text> ();
mytxt.text = num.ToString ();
Image Imgy = GameObject.Find ("Canvas/Panel/Image").GetComponent<image>();
Imgy.sprite=Resources.Load<sprite>("Image/"+num) as Sprite;
}
}
</sprite></image></text>
沒有留言:
張貼留言