您的位置:首页 > 移动开发 > Unity3D

Unity3d ugui 实现image代码换图

2019-03-13 13:37 239 查看

核心脚本代码

Image IMGE = transform.Find(“IMGE”).GetComponent();
Sprite sprite1 = Resources.Load(“Textrues/yutujing”, typeof(Sprite)) as Sprite;
IMGE.sprite = sprite1;

需要注意的是 Resources.Load 会读取Assets中Resources目录下的资源, Resources目录需要手动创建
或者

public Sprite[] sprites;

public Sprite[] sprite1;
void Update ()
{

if (a>=200)
{
int Random1 = Random.Range(0,11);
for (int i = 0; i < 11; i++)
{
if (Random1==i)
{
image1 = Rt.transform.GetChild(0).transform.GetChild(0).GetComponent<Image>();

image2 = Rt.transform.GetChild(0).transform.GetChild(1).GetComponent<Image>();

image1.sprite=sprites[Random1];

image2.sprite=sprite1[Random1];

}
}

Instantiate(Rt,new Vector3 ( Random.Range (-860,850), 1, Random.Range (-717,-500)), Quaternion.Euler(new Vector3(0,0,0)));

a=1;

}else
{
a=a+1;
}

Debug.Log(a);

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: