亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Unity實(shí)現(xiàn)老虎機(jī)滾動(dòng)抽獎(jiǎng)效果的示例代碼

 更新時(shí)間:2021年04月26日 09:55:22   作者:佛系老陳  
這篇文章主要介紹了Unity實(shí)現(xiàn)老虎機(jī)滾動(dòng)抽獎(jiǎng)效果的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

直接看下效果圖吧:

choujiang

制作思路:

設(shè)計(jì)四張圖片,五個(gè)點(diǎn),每個(gè)圖片同時(shí)向下一個(gè)點(diǎn)移動(dòng),到最后一個(gè)就回到0號(hào)點(diǎn),以此循環(huán)。

1.2

場(chǎng)景搭建:

  • 創(chuàng)建Image命名為Bg作為電視框背景;
  • 創(chuàng)建Image命名Mask并添加Mask組件作為電視框內(nèi)容顯示遮罩框;
  • 創(chuàng)建四個(gè)Image作為滾動(dòng)圖片;
  • 創(chuàng)建開(kāi)始抽獎(jiǎng)按鈕;

1.3

PS:實(shí)際項(xiàng)目中可以根據(jù)需求來(lái)動(dòng)態(tài)修改圖片顯示,以達(dá)到的控制每次抽獎(jiǎng)獎(jiǎng)品內(nèi)容。

源碼分享:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class ScollToDraw : MonoBehaviour
{
      // 抽獎(jiǎng)按鈕
      public Button DrowBtn;
      
      // 獎(jiǎng)勵(lì)圖片
      public Image[] ArardImgArr;

      // 轉(zhuǎn)盤(pán)速度
      public float AniMoveSpeed = 3f;

      // 進(jìn)度
      private float[] progress = new[] {0f, 1f, 2f, 3f, 4f};

      // 轉(zhuǎn)動(dòng)動(dòng)畫(huà)位置
      private Vector3[] AniPosV3 = new[]
            {Vector3.up * 240, Vector3.up * 120, Vector3.zero, Vector3.down * 120, Vector3.down * 240};

      // 自動(dòng)暫停標(biāo)識(shí)
      private bool isAutoStop;
      // 抽獎(jiǎng)結(jié)束 停止刷新界面UI
      private bool isStopUpdatePos;
      
      void Start()
      {
            DrowBtn.onClick.AddListener(DrawFun);
            isAutoStop = false;
            isStopUpdatePos = false;
      }

      void Update()
      {
            if (isStopUpdatePos) return;
            
            float t = Time.deltaTime * AniMoveSpeed;
            for (int i = 0; i < ArardImgArr.Length; i++)
            {
                  progress[i] += t;
                  ArardImgArr[i].transform.localPosition = MovePosition(i);
            }
      }
      
      // 獲取下一個(gè)移動(dòng)到的位置
      Vector3 MovePosition(int i)
      {
            int index = Mathf.FloorToInt(progress[i]);
            if (index > AniPosV3.Length - 2)
            {
                  //保留其小數(shù)部分,不能直接賦值為0
                  progress[i] -= index; 
                  index = 0;
                  // 索引為2的到底了,索引為0的就在正中心
                  if (i == 2 && isAutoStop)
                  {
                        isStopUpdatePos = true;
                        Debug.Log("展示獎(jiǎng)勵(lì)界面...");
                        // todo...獲取獎(jiǎng)勵(lì)數(shù)據(jù)維護(hù)
                  }
                  return AniPosV3[index];
            }
            else
            {
                  return Vector3.Lerp(AniPosV3[index], AniPosV3[index + 1], progress[i] - index);
            }
      }
      
      /// <summary>
      /// 點(diǎn)擊抽獎(jiǎng)
      /// </summary>
      void DrawFun()
      {
            isAutoStop = false;
            isStopUpdatePos = false;
            StartCoroutine(SetMoveSpeed(2));
            // DoTween 按鈕下拉動(dòng)畫(huà)
            // Transform tran = DrowBtn.transform;
            //tran.DOLocalMoveY(-60, 0.2f).OnComplete(() =>
            //{
            //      tran.DOLocalMoveY(50, 0.2f);
            //
            //});
      }
      
      // 抽獎(jiǎng)動(dòng)畫(huà)速度控制
      IEnumerator SetMoveSpeed(int time)
      {
            AniMoveSpeed = 10;
            yield return new WaitForSeconds(time);
            AniMoveSpeed = 1;
            yield return new WaitForSeconds(time);
            isAutoStop = true;
      }
}

到此這篇關(guān)于Unity實(shí)現(xiàn)老虎機(jī)滾動(dòng)抽獎(jiǎng)效果的示例代碼的文章就介紹到這了,更多相關(guān)Unity老虎機(jī)滾動(dòng)抽獎(jiǎng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論