VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之Unity3d ugui 实现image代码换图

核心脚本代码

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

    }
}


相关教程