You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
879 B
C#
30 lines
879 B
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Events;
|
|
|
|
public class TWS_JoystickTouchZone : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
|
{
|
|
[Header("Rect References")]
|
|
public RectTransform containerRect;
|
|
|
|
public UIVirtualJoystick joystick;
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
joystick.gameObject.SetActive(true);
|
|
joystick.transform.position = eventData.position;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out Vector2 position);
|
|
|
|
joystick.OnDrag(eventData);
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
joystick.OnPointerUp(eventData);
|
|
joystick.gameObject.SetActive(false);
|
|
}
|
|
} |