Unity实现跑马灯抽奖效果
程序员文章站
2023-11-24 16:18:04
unity 跑马灯抽奖效果实现代码,供大家参考,具体内容如下
这边用到插件是ngui+dotween,思路简单说下:先排版,通过移动图片蒙版来实现效果。
下面是排版和文...
unity 跑马灯抽奖效果实现代码,供大家参考,具体内容如下
这边用到插件是ngui+dotween,思路简单说下:先排版,通过移动图片蒙版来实现效果。
下面是排版和文件目录。
代码部分是通过余数去确认停的位置,boxlist通过unity拖拉加入数据,chooseboxlist直接通过余数判断添加。
代码量很少,稍微看下就明白了。
直接上代码了:
using system; using system.collections; using system.collections.generic; using dg.tweening; using unityengine; public class goluckydraw : monobehaviour { private int index = 23; //index%12 来判断停在哪个位置 // use this for initialization private uisprite prize1,prize2,prize3,prize4,prize5,prize6,prize7,prize8,prize9,prize10,prize11,prize12, prize13, prize14; private uisprite transparentbox; public list<transform> boxlist = new list<transform>(); public list<transform> chooseboxlist = new list<transform>(); void start () { prize1 = gameobject.find("lucky/bg/prize1").getcomponent<uisprite>(); prize2 = gameobject.find("lucky/bg/prize2").getcomponent<uisprite>(); prize3 = gameobject.find("lucky/bg/prize3").getcomponent<uisprite>(); prize4 = gameobject.find("lucky/bg/prize4").getcomponent<uisprite>(); prize5 = gameobject.find("lucky/bg/prize5").getcomponent<uisprite>(); prize6 = gameobject.find("lucky/bg/prize6").getcomponent<uisprite>(); prize7 = gameobject.find("lucky/bg/prize7").getcomponent<uisprite>(); prize8 = gameobject.find("lucky/bg/prize8").getcomponent<uisprite>(); prize9 = gameobject.find("lucky/bg/prize9").getcomponent<uisprite>(); prize10 = gameobject.find("lucky/bg/prize10").getcomponent<uisprite>(); prize11 = gameobject.find("lucky/bg/prize11").getcomponent<uisprite>(); prize12 = gameobject.find("lucky/bg/prize12").getcomponent<uisprite>(); prize13 = gameobject.find("lucky/bg/prize13").getcomponent<uisprite>(); prize14 = gameobject.find("lucky/bg/prize14").getcomponent<uisprite>(); transparentbox = gameobject.find("bg/transparentbox").getcomponent<uisprite>(); transparentbox.gameobject.setactive(false); //获取需要监听的按钮对象 gameobject button = gameobject.find("lucky/bg/start"); //设置这个按钮的监听,指向本类的buttonclick方法中。 uieventlistener.get(button).onclick = startluckydraw; chooseindex(index); // startluckydraw(); } ienumerator move( ) { float time; for (int i = 0; i < boxlist.count; i++) { time = mathf.lerp(0.04f, 0.05f, 0.05f*i); debug.log("---time----="+time); transparentbox.transform.dolocalmove(boxlist[i].localposition, time); yield return new waitforseconds(0.05f); } for (int i = 0; i < boxlist.count; i++) { time = mathf.lerp(0.05f, 0.065f, 0.05f * i); debug.log("---time3----=" + time); transparentbox.transform.dolocalmove(boxlist[i].localposition, time); yield return new waitforseconds(0.05f); } for (int i = 0; i < boxlist.count; i++) { time = mathf.lerp(0.065f, 0.08f, 0.05f * i); debug.log("---time2----=" + time); transparentbox.transform.dolocalmove(boxlist[i].localposition, time); yield return new waitforseconds(0.05f); } for (int i = 0; i < chooseboxlist.count; i++) { transparentbox.transform.dolocalmove(chooseboxlist[i].localposition,0.1f); yield return new waitforseconds(0.1f); } yield return new waitforseconds(2f); transparentbox.gameobject.setactive(false); } private void chooseindex(int index) { chooseboxlist.clear(); for (int i = 0; i < index % 12; i++) { chooseboxlist.add(boxlist[i]); } } private void startluckydraw(gameobject go) { transparentbox.gameobject.setactive(true); startcoroutine(move()); } void update () { } }
代码很糙,大家自己完善吧!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: HTML5 语音搜索只需一句代码