日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity 白猫操作小实例

發布時間:2024/8/24 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 白猫操作小实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。