unity 鼠标手势的左右滑动

来源:互联网 发布:检测电脑温度软件 编辑:程序博客网 时间:2024/05/01 17:22
using UnityEngine;using System.Collections;public class HeroModelRotate : MonoBehaviour{    /// <summary>    /// 第一次按下的位置    /// </summary>    private Vector2 first = Vector2.zero;    /// <summary>    /// 鼠标的拖拽位置(第二次的位置)    /// </summary>    private Vector2 second = Vector2.zero;    /// <summary>    /// 旋转的角度    /// </summary>    private float angle = 3f;    void OnGUI()    {        if (Event.current.type == EventType.MouseDown)        {            //记录鼠标按下的位置               first = Event.current.mousePosition;        }        if (Event.current.type == EventType.MouseDrag)        {            //记录鼠标拖动的位置               second = Event.current.mousePosition;            if (second.x < first.x)            {                //拖动的位置的x坐标比按下的位置的x坐标小时,响应向左事件                   this.transform.Rotate(Vector3.up, angle);            }            if (second.x > first.x)            {                //拖动的位置的x坐标比按下的位置的x坐标大时,响应向右事件                   this.transform.Rotate(Vector3.down, angle);            }            first = second;        }    }}

0 0
原创粉丝点击