Unity 白猫操作小实例
生活随笔
收集整理的這篇文章主要介紹了
Unity 白猫操作小实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近師兄找我說白貓的操作如何做,? 0.0 結果白貓沒有android的客戶端玩不了,看了下視頻介紹就簡單做了下
效果圖:
?
核心代碼:
using UnityEngine; using System.Collections; using System.Collections.Generic; using System;public class Test : MonoBehaviour {private Test() { }private Vector3 startMouseDown;private Vector3 lastMouseDown;private float pressTimer;private bool isCounter; //開始計數private bool isDrag; //開始拖動private bool isLasting; //開始持久點擊public float pressTime; //單擊public float pressLastingTime; //持久點擊public float dragDistance; //拖動大于多少才開始生效#region 事件public static Action<Vector3> StartPressEvent;public static Action<Vector3> EndPressEvent;public static Action<Vector3> StartDragEvent;public static Action<Vector3> EndDragEvent;public static Action<Vector3> StartLastingEvent;public static Action<Vector3> EndLastingEvent;#endregion#region 測試方法void Awake(){StartPressEvent += StartPress;EndPressEvent += EndPress;StartDragEvent += StartDrag;EndDragEvent += EndDrag;StartLastingEvent += StartLasting;EndLastingEvent += EndLasting;}private void StartPress(Vector3 v){Debug.Log("開始單擊事件");}private void EndPress(Vector3 v){Debug.Log("結束單擊事件");}private void StartDrag(Vector3 v){Debug.Log("開始拖動事件");}private void EndDrag(Vector3 v){Debug.Log("結束拖動事件");}private void StartLasting(Vector3 v){Debug.Log("開始持續點擊事件");}private void EndLasting(Vector3 v){Debug.Log("結束持續點擊事件");}#endregion// Update is called once per framevoid Update () {if (Input.GetMouseButtonDown(0)){isCounter = true;startMouseDown = Input.mousePosition;}if (Input.GetMouseButtonUp(0)){lastMouseDown = Input.mousePosition;isCounter = false;if (isDrag) {//拖動if (EndDragEvent != null) EndDragEvent(Input.mousePosition);isDrag = false;}else if (isLasting) {//持久點擊if (EndLastingEvent != null) EndLastingEvent(Input.mousePosition);isLasting = false;}else {//單擊if (EndPressEvent != null) EndPressEvent(Input.mousePosition);}}if (isCounter){//開始計數pressTimer += Time.deltaTime;}else {if (pressTimer > 0 && pressTimer < pressTime){Debug.Log("單擊");if (StartPressEvent != null) StartPressEvent(Input.mousePosition);}pressTimer = 0f;}if (isCounter && Mathf.Abs(Vector3.Distance(startMouseDown, Input.mousePosition)) > dragDistance && isLasting == false){Debug.Log("正在拖動");isDrag = true;if (StartDragEvent != null) StartDragEvent(Input.mousePosition);//讓人物跟誰手指的方向移動return;}if (isCounter && pressTimer > pressLastingTime && isDrag == false){Debug.Log("持久點擊");isLasting = true;if (StartLastingEvent != null) StartLastingEvent(Input.mousePosition);//出現技能圖標,然后滑動到技能哪里就可以觸發技能return;}}}?
Unity5 + UGUI制作
完整的demo: http://yunpan.cn/cjHbIaXvzemax? 訪問密碼 7607
轉載于:https://www.cnblogs.com/plateFace/p/4474072.html
總結
以上是生活随笔為你收集整理的Unity 白猫操作小实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JVM性能调优(转)
- 下一篇: Core Java笔记 6.部署应用程序