Unity 주마등 추첨 효과 실현

Unity 주마등 추첨 효과 실현 코드 를 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
여기 서 플러그 인 을 사용 하 는 것 은 NGUI+Dotween 입 니 다.생각 은 간단하게 말 하면 먼저 레이아웃 을 하고 모 바 일 사진 을 통 해 효 과 를 실현 합 니 다.
다음은 조판 과 파일 디 렉 터 리 입 니 다.

코드 부분 은 잔 수 를 통 해 멈 춘 위 치 를 확인 하고 box list 는 유 니 티 드래그 를 통 해 데 이 터 를 추가 하 며 chooseBox List 는 잔 수 를 통 해 직접 판단 하여 추가 합 니 다.
코드 양 이 적어 서 조금 만 보면 알 수 있 습 니 다.
코드 가 바로 올 라 갑 니 다:

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 () {
 
 }
}
코드 가 매우 거 칠 니 모두 스스로 보완 하 세 요!
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기