前几天需要实现一个选择功能,也就是一排按钮,选择哪一个,那个按钮变色,并且选择到某个对象,上网查了很多,但是没有,就自己用堆写了一个,在这跟大家分享。


好像插不了图片,那我直接上代码吧:

//选择是那块区域地板//点击事件(点击一个按钮会变成想要的图片)publicvoidAnniuOnClick(GameObjectgame){//要换的图集和图片名字game.GetComponent<UISprite>().atlas=atas;game.GetComponent<UISprite>().spriteName="an_01";//将点的按钮存进堆中currentGame.Enqueue(game);if(currentGame.Count>1){//点击存入第二个时,第一个变原来的颜色,并出堆currentGame.Peek().GetComponent<UISprite>().atlas=atas;currentGame.Peek().GetComponent<UISprite>().spriteName="anlv_01";currentGame.Dequeue();}Debug.Log(currentGame.Peek());//将当前的存起来previesGame=currentGame.Peek();//要实现的功能在下边方法中StoreDIBan(currentGame.Peek());isArea=true;}

其他的就不多说了,只要堆得核心思想,“先进先出,后进后出”对了,这个很好写。。。。