Unity 跑馬燈抽獎(jiǎng)效果實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
倉(cāng)山ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
這邊用到插件是NGUI+Dotween,思路簡(jiǎn)單說(shuō)下:先排版,通過(guò)移動(dòng)圖片蒙版來(lái)實(shí)現(xiàn)效果。
下面是排版和文件目錄。
代碼部分是通過(guò)余數(shù)去確認(rèn)停的位置,boxlist通過(guò)unity拖拉加入數(shù)據(jù),chooseBoxList直接通過(guò)余數(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 來(lái)判斷停在哪個(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 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); //獲取需要監(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 () { } }
代碼很糙,大家自己完善吧!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
本文題目:Unity實(shí)現(xiàn)跑馬燈抽獎(jiǎng)效果
當(dāng)前網(wǎng)址:http://aaarwkj.com/article6/pdisig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、標(biāo)簽優(yōu)化、微信公眾號(hào)、ChatGPT、響應(yīng)式網(wǎng)站、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)