首先創建一個canvas,然后創建一個panel,panel底下有image,button按鈕,還有point指標,還有show空白圖片和hint文本

然后在canvas上掛載代碼
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialRotation : MonoBehaviour
{
public Transform _dial;//轉盤
public GameObject _showResult;
public Text _hintText;
private bool _isPause = true;//是否為停止狀態
private int _last = 0;//上次旋轉的 %360
private int _cyclesNum = 10;//旋轉的整圈數
private float _duration = 3;//旋轉的持續時長
private void Start()
{
_hintText = GameObject.Find("Hint").GetComponent<Text>();
_showResult.gameObject.SetActive(false);
}
public void RotationOnClick()
{
_showResult.gameObject.SetActive(false);
if (_isPause)
{
_isPause = false;
int a = 0;
//隨機60度的倍數
int rotNum = Random.Range(1, 7);
a = _cyclesNum * 360 + rotNum * 60;
Debug.Log("本次旋轉的度數: " + (a - _last) + "\r\n" + "本次隨機的結果: " + rotNum);
//本次旋轉的度數
_dial.DORotate(new Vector3(0, 0, a - _last), _duration, RotateMode.FastBeyond360).SetEase(Ease.OutQuad).OnComplete(delegate {
_isPause = true;
//因為每次旋轉后轉盤沒有歸零,就必須減去上次的%360度數
_last = rotNum * 60;
_showResult.gameObject.SetActive(true);
switch (rotNum)
{
case 1:
_hintText.text = "獲得紀念T恤一件";
Debug.Log("獲得紀念T恤一件"); break;
case 2:
_hintText.text = "獲得50元代金券";
Debug.Log("獲得50元代金券"); break;
case 3:
_hintText.text = "謝謝惠顧";
Debug.Log("謝謝惠顧"); break;
case 4:
Debug.Log("獲得20元代金券");
_hintText.text = "獲得20元代金券"; break;
case 5:
Debug.Log("獲得萬能介面一個");
_hintText.text = "獲得萬能介面一個"; break;
case 6:
Debug.Log("獲得t2手機一部");
_hintText.text = "獲得t2手機一部"; break;
default:
break;
}
});
}
}
}
然后拖入doween插件
隨后將他們拖進去

然后將他的按鈕點擊

最后給大家吧插件上傳了
鏈接:https://pan.baidu.com/s/1rkrveEz2EuAU9fEhbR5Wgg
提取碼:ziai
復制這段內容后打開百度網盤手機App,操作更方便哦
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/245704.html
標籤:其他
下一篇:安卓中的虛擬鍵盤實作,KeyEvent的事件分發、處理機制。EditText是如何將KeyEvent事件轉為字符輸入的?
