您的位置:首页 > 产品设计 > UI/UE

NGUI使用图集的精灵换图片

2015-09-10 20:49 399 查看
    创建了一个sprite,选择的是某一个图集下的sprite,现在我想点击它来换图片。前提是你的sprite已经加了UIButton

 代码如下:   

public void OnClick()
{
if (this.GetComponent<UIButton>().normalSprite == "picture1")
{
this.GetComponent<UISprite>().spriteName = "picture2";
this.GetComponent<UIButton>().normalSprite = "picture2";
return;
}
if (this.GetComponent<UIButton>().normalSprite == "picture2")
{
this.GetComponent<UISprite>().spriteName = "picture1";
this.GetComponent<UIButton>().normalSprite = "picture1";
return;
}
}


   这个可以做对话,但是不推荐,比如你的对话有五十个,那你要用五十张图片。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: