3种转盘抽奖动画效果实现
来源:互联网 发布:java前端和后端的工资 编辑:程序博客网 时间:2024/04/29 20:18
很多游戏里面会涉及到各种抽奖系统(基本都是假随机,都懂的),这里实现了3种转盘相关的简单抽奖,希望对你有帮助!
using UnityEngine;using System.Collections;using UnityEngine.UI;using DG.Tweening;public class LuckDraw : MonoBehaviour { //箭头,物品节点, 框选 public Transform _Arrow, _Awards, _Kuang; public Transform[] _AwardList;//物品列表 public InputField _InputField;//输入框,输入0~7 Tweener _tweener = null;//动画 int _rollTimes = 5;//圈数 int _index_1, index_2 = 0;//下标1(结果), 下标2(物品下标) bool _playKuang = false;//框动画播放标志// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () { //转盘转动的时候,让物品保持原来的角度 for (int i = 0; i < _AwardList.Length; ++i) { _AwardList[i].eulerAngles = Vector3.zero; } if (_playKuang) { PlayKuang(); }} bool GetIndex() { if (!int.TryParse(_InputField.text, out _index_1)) { return false; } _index_1 = int.Parse(_InputField.text);//0~7; if (_index_1 < 0 || _index_1 > 7) { return false; } return true; } /// <summary> /// 箭头转动 /// </summary> public void ArrowRoll() { if (!GetIndex()) return; float angle = -90 - _rollTimes * 360 - _index_1 * 360 / 8.0f;//角度 //RotateMode.FastBeyond360第一圈不计算在_rollTimes中 _tweener = _Arrow.DORotate(new Vector3(0, 0, angle), 2.0f, RotateMode.FastBeyond360); //_tweener.SetEase(Ease.Flash);//这里可以设置动画效果 } public void BtnEvent_0() { ArrowRoll(); } /// <summary> /// 转盘转动 /// </summary> public void BtnEvent_1() { if (!GetIndex()) return; float angle = 5 * 360 + _index_1 * 360 / 8.0f;//角度 _tweener = _Awards.DORotate(new Vector3(0, 0, angle), 2.0f, RotateMode.FastBeyond360); } public void BtnEvent_2() { if (!GetIndex()) return; _Kuang.gameObject.SetActive(true); _playKuang = true; //InvokeRepeating("Kuang", 0.01f, 0.5f); } int kuang_rollTimes = 0; void PlayKuang() { //转满动画圈数后 if (kuang_rollTimes == _rollTimes) { if (index_2 < _index_1) { index_2++; _Kuang.position = _AwardList[index_2].position; Debug.Log("框下标2:" + index_2); } else { _playKuang = false; } } else//前几圈只是动画 { if (index_2 == 8) { index_2 = 0; kuang_rollTimes++; } _Kuang.position = _AwardList[index_2].position; index_2++; if (kuang_rollTimes == _rollTimes) index_2 = 0; } }}
特别说明:没有写初始化,请每次测试的时候重新运行!!!!!!
阅读全文
1 0
- 3种转盘抽奖动画效果实现
- Android实现抽奖转盘动画
- Android 抽奖 转盘 动画 实现原理详解
- java实现转盘抽奖;
- SurfaceView 实现 转盘抽奖
- SurfaceView 实现 转盘抽奖
- Android实现抽奖转盘
- 转盘抽奖js实现
- 抽奖转盘实现 surfaceView
- COCOS抽奖转盘实现
- 挑战2:实现一个转盘大抽奖(老虎机效果)
- iOS抽奖转盘动画之CAAnimation动画
- 利用jqueryRotare实现抽奖转盘
- 利用jqueryRotare实现抽奖转盘
- Cocos2d js 实现转盘抽奖
- 借助CCAction实现转盘抽奖
- 利用jqueryRotare实现抽奖转盘
- 利用SurfaceView实现转盘抽奖
- 挑战程序竞赛系列(93):3.6凸包(4)
- 怎么免费恢复手机里删除的照片呢?
- SSD相关基础
- 关于JavaWeb的实例(一)-以eclipse搭建SSH框架
- Vue2.0与 [百度地图] 结合使用———vue+webpack+axios+百度地图实现组件之间的通信
- 3种转盘抽奖动画效果实现
- 【greenDAO3】 项目搭建与增删改查操作
- svn ignore 的用法(忽略文件及目录)
- 【项目实战经验】电商系统常用数据结构
- ARP协议工作原理[同网段及跨网段]
- 拖了将近一个月的----C++初学之路
- TP 框架实现支付宝接口功能
- 百度java后台实习生面试题
- Inter Edison平台CPU、MCU双核架构