//using UnityEngine;
|
//using UnityEngine.EventSystems;
|
//using UnityEngine.UI;
|
|
|
//public class MouseControlled3DJoystick : MonoBehaviour
|
//{
|
|
// public Transform joystickHandle;
|
// public float joystickRange = 0.05f; // ¹ÌÅÍ ´ÜÀ§
|
// public LayerMask joystickLayer;
|
|
// private Vector3 initialHandlePosition;
|
// private Vector3 currentHandlePosition;
|
// private bool isDragging = false;
|
// private Camera mainCamera;
|
|
// private void Start()
|
// {
|
// initialHandlePosition = joystickHandle.localPosition;
|
// currentHandlePosition = initialHandlePosition;
|
// mainCamera = Camera.main;
|
// }
|
|
// private void Update()
|
// {
|
// if (Input.GetMouseButtonDown(1))
|
// {
|
// Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
// RaycastHit hit;
|
|
// if (Physics.Raycast(ray, out hit, Mathf.Infinity, joystickLayer))
|
// {
|
// if (hit.transform == joystickHandle)
|
// {
|
// isDragging = true;
|
// }
|
// }
|
// }
|
|
// if (Input.GetMouseButtonUp(1))
|
// {
|
// isDragging = false;
|
// // Á¶À̽ºÆ½À» ¿øÀ§Ä¡·Î µÇµ¹¸³´Ï´Ù
|
// joystickHandle.localPosition = initialHandlePosition;
|
// currentHandlePosition = initialHandlePosition;
|
// }
|
|
// if (isDragging)
|
// {
|
// Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
// Plane plane = new Plane(joystickBase.up, joystickBase.position);
|
|
// float distance;
|
// if (plane.Raycast(ray, out distance))
|
// {
|
// Vector3 hitPoint = ray.GetPoint(distance);
|
// Vector3 localHitPoint = joystickBase.InverseTransformPoint(hitPoint);
|
|
// // XZ Æò¸é¿¡¼ÀÇ À̵¿À» Á¦ÇÑÇÕ´Ï´Ù
|
// Vector2 joystickPosition = new Vector2(localHitPoint.x, localHitPoint.z);
|
// joystickPosition = Vector2.ClampMagnitude(joystickPosition, joystickRange);
|
|
// Vector3 newPosition = new Vector3(joystickPosition.x, initialHandlePosition.y, joystickPosition.y);
|
// joystickHandle.localPosition = newPosition;
|
// currentHandlePosition = newPosition;
|
// }
|
// }
|
// }
|
|
// public Vector2 GetInputVector()
|
// {
|
// Vector2 input = new Vector2(
|
// currentHandlePosition.x - initialHandlePosition.x,
|
// currentHandlePosition.z - initialHandlePosition.z
|
// );
|
// return input / joystickRange;
|
// }
|
//}
|