1、首先创建一个3D物体 代表主角Player。和两个Image充当摇杆,在Joy物体上挂上Event Trigger。
2、创建两个脚本GamePanel 和 PlayerObject分别挂在Player和Canvas。
3、GamePanel脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class GamePanel : MonoBehaviour
{
public EventTrigger et;
public RectTransform ImgJoy;
private PlayerObject player;
void Start()
{
player = FindObjectOfType<PlayerObject>();
//为摇杆注册事件
//拖动中
EventTrigger.Entry en = new