_xiaofang/xiaofang/Assets/Script/Character/DragTheScreen.cs
2024-11-20 14:37:08 +08:00

40 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DragTheScreen : MonoBehaviour, IDragHandler
{
public GameObject yg;
public GameObject Player;
private void Start()
{
yg.GetComponent<Joystick>().Drag += DragEvent;
yg.GetComponent<Joystick>().DragEnd += DragEnd;
}
public void OnDrag(PointerEventData eventData)//屏幕移动
{
Player.GetComponent<PlayerMovement_Jpystick>().HandleViewSwipe();
}
public void DragEvent(float x, float y, PointerEventData eventData)//摇杆移动
{
horizontal = x;
vertical = y;
}
public void DragEnd()//摇杆移动
{
horizontal = 0;
vertical = 0;
}
public float horizontal = 0;
public float vertical = 0;
public void Update()
{
if (horizontal != 0 || vertical != 0) Player.GetComponent<PlayerMovement_Jpystick>().HandleJoystickControl(horizontal, vertical);
}
}