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 ,