成都创新互联网站制作重庆分公司

Unity实现跑马灯抽奖效果-创新互联

Unity 跑马灯抽奖效果实现代码,供大家参考,具体内容如下

创新互联建站是一家专注于成都网站设计、成都网站制作与策划设计,平原网站建设哪家好?创新互联建站做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:平原等地区。平原做网站价格咨询:18980820575

这边用到插件是NGUI+Dotween,思路简单说下:先排版,通过移动图片蒙版来实现效果。
下面是排版和文件目录。

Unity实现跑马灯抽奖效果

代码部分是通过余数去确认停的位置,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 boxList = 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);
    //获取需要监听的按钮对象
    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 () {
 
 }
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:Unity实现跑马灯抽奖效果-创新互联
路径分享:http://cxhlcq.com/article/jjhce.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部