用NGUI动态添加和删除Sprite
usingUnityEngine;
usingSystem.Collections;
publicclassNGUI_button:MonoBehaviour{
publicUIButtonbutton1;
publicUIButtonbutton2;
voidStart(){
UIButtonexe1=button1.GetComponent<UIButton>();//获取组件的方式
UIButtonexe2=button2.GetComponent<UIButton>();
}
voidUpdate(){
}
voidopnedButton1(GameObjectobj)
{
if(obj.name=="Button01")
{
UIAtlasatlas=Resources.Load("Textrue/Atlas/TextAtlas",typeof(UIAtlas))asUIAtlas; //必须建一个Resources 文件夹 ,在他下面放制作好的图集
GameObjectparent=GameObject.Find("point"); //在U3D里面建一个空物体 在这个空物体身上加UIGrid这个脚本 .他时NGUI的脚本。
UISpritesprite=NGUITools.AddSprite(parent,atlas,"xiaofeiji");//要更换的图片名字
sprite.MakePixelPerfect();
parent.GetComponent<UIGrid>().repositionNow=true;
}
else
{
Destroy(GameObject.Find("Sprite"));//删除这个图片
}
}
}
//使用说明 先建一个UIroot 在他下面建2个Button ,
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。