国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

Unity實現跑馬燈抽獎效果

2020-01-24 00:10:03
字體:
來源:轉載
供稿:網友

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 () {  }}

代碼很糙,大家自己完善吧!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宿州市| 西贡区| 裕民县| 北海市| 德兴市| 延吉市| 钦州市| 牙克石市| 临湘市| 山阳县| 桂平市| 乐清市| 交口县| 荣昌县| 勐海县| 天门市| 敖汉旗| 新巴尔虎右旗| 临汾市| 常宁市| 柳河县| 同江市| 南岸区| 巴塘县| 宾川县| 乐至县| 城步| 新建县| 济源市| 定陶县| 丰城市| 正蓝旗| 揭阳市| 西藏| 宁德市| 东海县| 霸州市| 松阳县| 八宿县| 玛多县| 广安市|