除了在使用Eath Touch插件之外,可以进行手写摇杆,一个建议的摇杆也可以实现人物的移动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class GameTouch : MonoBehaviour,IDragHandler,IEndDragHandler,IBeginDragHandler
{
public static Vector2 offest;
private Vector2 startPos;
public void OnBeginDrag(PointerEventData eventData)
{
startPos = transform.position;
}
public void OnDrag(PointerEventData eventData)
{
offest = eventData.position - startPos;
transform.position = Vector2.ClampMagnitude(offest, 30) + startPos;
}
public void OnEndDrag(PointerEventData eventData)
{
offest=Vector2.zero;
transform.position = startPos;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube : MonoBehaviour
{
// Update is called once per frame
void Update()
{
transform.Translate(GameTouch.offest.y*Time.deltaTime*0.1f*Vector3.forward);
transform.Rotate(GameTouch.offest.x*Time.deltaTime*0.2f*Vector3.up);
}
}
三个Image组成,第一个半透明的图片 可有可无 第二个为大圆,用来限制的移动的半径,最后一个是中心,用来控制人物的移动