조이스틱으로 player 오브젝트 좌우 이동 로직 적용
This commit is contained in:
44
Gameton-06/Assets/Gameton/Scripts/Character/CharacterBase.cs
Normal file
44
Gameton-06/Assets/Gameton/Scripts/Character/CharacterBase.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class CharacterBase : MonoBehaviour
|
||||
{
|
||||
public float speed;
|
||||
public VariableJoystick joystick;
|
||||
public Rigidbody2D rb;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
joystick = ControllerUI.Instance.joystick;
|
||||
}
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
if (joystick != null)
|
||||
{
|
||||
Debug.Log($"Horizontal Input: {joystick.input.x}, {joystick.input.y}");
|
||||
Debug.Log($"Horizontal Horizontal: {joystick.Horizontal}");
|
||||
Debug.Log($"Horizontal Direction: {joystick.Direction}");
|
||||
|
||||
// 조이스틱의 Horizontal 값 가져오기
|
||||
float horizontalInput = joystick.Horizontal;
|
||||
|
||||
// 입력값이 0이 아닐 때만 처리
|
||||
if (Mathf.Abs(horizontalInput) > 0.0f)
|
||||
{
|
||||
// 현재 위치 가져오기
|
||||
Vector2 currentPosition = rb.position;
|
||||
|
||||
// 새로운 X 위치 계산
|
||||
float newXPosition = currentPosition.x + horizontalInput * speed * Time.fixedDeltaTime;
|
||||
|
||||
// Rigidbody2D의 위치 업데이트
|
||||
rb.MovePosition(new Vector2(newXPosition, currentPosition.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 163a5df0eeadca842adba0310b08b93e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,6 +6,14 @@ namespace TON
|
||||
{
|
||||
public class CharacterController : MonoBehaviour
|
||||
{
|
||||
|
||||
private CharacterBase linkedCharactor;
|
||||
|
||||
public LayerMask groundLayer;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
linkedCharactor = GetComponent<CharacterBase>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace TON
|
||||
{
|
||||
public class UIManager : SingletonBase<UIManager>
|
||||
{
|
||||
public VariableJoystick joystick; // Joystick 컴포넌트를 참조
|
||||
public static T Show<T>(UIList uiName) where T : UIBase
|
||||
{
|
||||
var targetUI = Singleton.GetUI<T>(uiName);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace TON
|
||||
private Canvas canvas;
|
||||
private Camera cam;
|
||||
|
||||
private Vector2 input = Vector2.zero;
|
||||
public Vector2 input = Vector2.zero;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
|
||||
@@ -3,10 +3,8 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
|
||||
namespace TON
|
||||
{
|
||||
|
||||
public class VariableJoystick : Joystick
|
||||
{
|
||||
public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace TON
|
||||
{
|
||||
public static ControllerUI Instance => UIManager.Singleton.GetUI<ControllerUI>(UIList.ControllerUI);
|
||||
|
||||
public VariableJoystick joystick;
|
||||
private void Start()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user