设为首页 加入收藏

TOP

Unity3d ugui 实现image代码换图
2019-09-17 18:24:58 】 浏览:24
Tags: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);

    }
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇WinForm中DataGridView的TextBoxC.. 下一篇asp.net core系列 41 Web 应用 MV..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目