Bootstrap

unity 获取物体运动方向


using UnityEngine;
using UnityEngine.EventSystems;

namespace Global

{
	public class Test : MonoBehaviour
    {

        private Vector3 _newPos;
        private Vector3 _oldPos;

        void Start()
        {
         

        }
		private void Update()
		{
            _newPos = transform.position;
            if (_oldPos.x > _newPos.x)
            {
                print("往右边滑动");

            }
            else if (_oldPos.x < _newPos.x)
            {
                print("往左边滑动");

            }
            else if (_oldPos.y > _newPos.y)
            {
                print("往下面滑动");
            }
            else if (_oldPos.y < _newPos.y)
            {
                print("往上面滑动");

            }
            _oldPos = _newPos;
        }
    }
}
;