57 lines
1.5 KiB
C#
57 lines
1.5 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;
|
|
public CameraControl CameraControl;
|
|
private bool isscanmove = true;
|
|
private void Start()
|
|
{
|
|
yg.GetComponent<Joystick>().Drag += DragEvent;
|
|
yg.GetComponent<Joystick>().DragEnd += DragEnd;
|
|
}
|
|
public void OnDrag(PointerEventData eventData)//屏幕移动
|
|
{
|
|
if (isscanmove)
|
|
{
|
|
|
|
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 (CameraControl.joystickController.joystickInput.magnitude > 0)
|
|
{
|
|
isscanmove = false;
|
|
if (horizontal != 0 || vertical != 0) Player.GetComponent<PlayerMovement_Jpystick>().HandleJoystickControl2(horizontal, vertical);
|
|
}
|
|
else
|
|
{
|
|
isscanmove = true;
|
|
if (horizontal != 0 || vertical != 0) Player.GetComponent<PlayerMovement_Jpystick>().HandleJoystickControl(horizontal, vertical);
|
|
}
|
|
|
|
}
|
|
}
|