68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class VoyagePlayerShipMovement : MonoBehaviour
|
|
{
|
|
private void Start()
|
|
{
|
|
#if UNITY_EDITOR
|
|
// 현재 방향을 표시할 LineRenderer 설정
|
|
forwardDirectionLine = CreateLineRenderer("CurrentDirectionLine", Color.green);
|
|
upDirectionLine = CreateLineRenderer("upDirectionLine", Color.yellow);
|
|
// 입력 방향을 표시할 LineRenderer 설정
|
|
inputDirectionLine = CreateLineRenderer("InputDirectionLine", Color.red);
|
|
#endif
|
|
}
|
|
|
|
public void OnMove(InputAction.CallbackContext context)
|
|
{
|
|
Vector2 inputVector = context.ReadValue<Vector2>();
|
|
|
|
Vector3 currentForward = transform.forward;
|
|
Vector3 currentUp = transform.up;
|
|
Vector3 inputDirection = new Vector3(inputVector.x, 0, inputVector.y).normalized;
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
DrawDebugLine(forwardDirectionLine, currentForward);
|
|
DrawDebugLine(upDirectionLine, currentUp);
|
|
DrawDebugLine(inputDirectionLine, inputDirection);
|
|
#endif
|
|
}
|
|
|
|
// Debug draw below...
|
|
#if UNITY_EDITOR
|
|
private LineRenderer inputDirectionLine;
|
|
private LineRenderer forwardDirectionLine;
|
|
private LineRenderer upDirectionLine;
|
|
private LineRenderer CreateLineRenderer(string name, Color color)
|
|
{
|
|
GameObject lineObj = new GameObject(name);
|
|
lineObj.transform.SetParent(transform);
|
|
LineRenderer line = lineObj.AddComponent<LineRenderer>();
|
|
|
|
// LineRenderer 기본 설정
|
|
line.startWidth = 0.1f;
|
|
line.endWidth = 0.1f;
|
|
line.material = new Material(Shader.Find("Universal Render Pipeline/Unlit"));
|
|
line.startColor = color;
|
|
line.endColor = color;
|
|
line.positionCount = 2;
|
|
|
|
line.material.color = color;
|
|
|
|
return line;
|
|
}
|
|
private void DrawDebugLine(LineRenderer renderer, Vector3 direction)
|
|
{
|
|
const float lineLength = 4;
|
|
Vector3 position = transform.position;
|
|
// 현재 방향 라인 업데이트 (파란색)
|
|
renderer.SetPosition(0, position);
|
|
renderer.SetPosition(1, position + direction * lineLength);
|
|
}
|
|
#endif
|
|
} |