using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Joystick : MonoBehaviour, IDragHandler, IEndDragHandler
{
private readonly int maxDistance = 150;
public Vector2 joystickDirection { get { return this.transform.localPosition.normalized; } }
public void OnDrag(PointerEventData eventData)
{
this.transform.position = Input.mousePosition;
if (this.transform.localPosition.magnitude > maxDistance)
{
this.transform.localPosition = this.transform.localPosition.normalized * maxDistance;
}
}
public void OnEndDrag(PointerEventData eventData)
{
this.transform.localPosition = Vector3.zero;
}
}
摇杆(magnitude)
最新推荐文章于 2024-08-21 18:18:02 发布