实现功能:点击一定范围内的屏幕,以点击点为中心生成一个摇杆,移动摇杆可以控制物体的移动。
ui布局比较简单,
Limit-yaogan决定摇杆的活动范围
yaoganDI大圈
yaogan小圈
摇杆脚本部分的:需要引用三个拖拽的接口,用来达到摇杆的效果。IPointerDownHandler,IDragHandler,IPointerUpHandler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class YaoganMager : MonoBehaviour,IPointerDownHandler,IDragHandler,IPointerUpHandler
{
public float r; //半径
public Vector2 placeValue; //位置
public float pull;//拉扯
/// <summary>
/// 点击过程中两种情况
/// 1、推拽在大圈里,直接获取位置就可以了
/// 2、拖拽小圈在大圈外,获取方向标准化*半径,再加上大圈的位置,就可以限定住小圈,最远也是只能超出半径
/// </summary>
/// <param name="eventData"></param>