Unity 跑馬燈抽獎(jiǎng)效果實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作與策劃設(shè)計(jì),平原網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:平原等地區(qū)。平原做網(wǎng)站價(jià)格咨詢:18980820575這邊用到插件是NGUI+Dotween,思路簡單說下:先排版,通過移動(dòng)圖片蒙版來實(shí)現(xiàn)效果。
下面是排版和文件目錄。
代碼部分是通過余數(shù)去確認(rèn)停的位置,boxlist通過unity拖拉加入數(shù)據(jù),chooseBoxList直接通過余數(shù)判斷添加。
代碼量很少,稍微看下就明白了。
直接上代碼了:
using System; using System.Collections; using System.Collections.Generic; using DG.Tweening; using UnityEngine; public class goLuckyDraw : MonoBehaviour { private int index = 23; //index%12 來判斷停在哪個(gè)位置 // Use this for initialization private UISprite prize1,prize2,prize3,prize4,prize5,prize6,prize7,prize8,prize9,prize10,prize11,prize12, prize13, prize14; private UISprite transparentBox; public ListboxList = new List (); public List chooseBoxList = new List (); void Start () { prize1 = GameObject.Find("Lucky/Bg/prize1").GetComponent (); prize2 = GameObject.Find("Lucky/Bg/prize2").GetComponent (); prize3 = GameObject.Find("Lucky/Bg/prize3").GetComponent (); prize4 = GameObject.Find("Lucky/Bg/prize4").GetComponent (); prize5 = GameObject.Find("Lucky/Bg/prize5").GetComponent (); prize6 = GameObject.Find("Lucky/Bg/prize6").GetComponent (); prize7 = GameObject.Find("Lucky/Bg/prize7").GetComponent (); prize8 = GameObject.Find("Lucky/Bg/prize8").GetComponent (); prize9 = GameObject.Find("Lucky/Bg/prize9").GetComponent (); prize10 = GameObject.Find("Lucky/Bg/prize10").GetComponent (); prize11 = GameObject.Find("Lucky/Bg/prize11").GetComponent (); prize12 = GameObject.Find("Lucky/Bg/prize12").GetComponent (); prize13 = GameObject.Find("Lucky/Bg/prize13").GetComponent (); prize14 = GameObject.Find("Lucky/Bg/prize14").GetComponent (); transparentBox = GameObject.Find("Bg/Transparentbox").GetComponent (); transparentBox.gameObject.SetActive(false); //獲取需要監(jiān)聽的按鈕對(duì)象 GameObject button = GameObject.Find("Lucky/Bg/start"); //設(shè)置這個(gè)按鈕的監(jiān)聽,指向本類的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 () { } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。