核心脚本代码
Image IMGE = transform.Find("IMGE").GetComponent<Image>();
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);
}
}