summaryrefslogtreecommitdiff
path: root/Assets/Scripts/PlayerController.cs
diff options
context:
space:
mode:
authorSmallFox <2806143047@qq.com>2026-01-30 23:10:03 +0800
committerSmallFox <2806143047@qq.com>2026-01-30 23:10:03 +0800
commit28fbde36e76429bfb2bf577d9e3da77db745ef3d (patch)
tree03392014566a11be31f8bfe59b3a5416e7ce33a2 /Assets/Scripts/PlayerController.cs
parent87aacebb8431b402d6a18054a81c4542632008d7 (diff)
parentbdd0c3eee905c5dc6fcf22344f7fdbd4cc3e3a02 (diff)
Merge branch 'main' of catilgrass.cn:GameJamTemplate into dev_lys
Diffstat (limited to 'Assets/Scripts/PlayerController.cs')
-rw-r--r--Assets/Scripts/PlayerController.cs10
1 files changed, 8 insertions, 2 deletions
diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs
index 10bde44..c107e19 100644
--- a/Assets/Scripts/PlayerController.cs
+++ b/Assets/Scripts/PlayerController.cs
@@ -12,6 +12,8 @@ public class PlayerMove3D : MonoBehaviour
[Tooltip("是否使用物理系统(Rigidbody)移动")]
public bool useRigidbody = true;
+ public bool player2;
+
// 3D物理组件引用
private Rigidbody rb;
@@ -56,8 +58,12 @@ public class PlayerMove3D : MonoBehaviour
private void MoveByTransform()
{
// 1. 获取Input Manager的水平/垂直输入(返回值范围:-1 ~ 1)
- float horizontalInput = Input.GetAxis("Horizontal"); // 左右:A/D 或 左/右方向键
- float verticalInput = Input.GetAxis("Vertical"); // 前后:W/S 或 上/下方向键
+ float horizontalInput = player2 ?
+ (Input.GetKey(KeyCode.LeftArrow) ? -1 : 0) + (Input.GetKey(KeyCode.RightArrow) ? 1 : 0) :
+ (Input.GetKey(KeyCode.A) ? -1 : 0) + (Input.GetKey(KeyCode.D) ? 1 : 0);
+ float verticalInput = player2 ?
+ (Input.GetKey(KeyCode.DownArrow) ? -1 : 0) + (Input.GetKey(KeyCode.UpArrow) ? 1 : 0) :
+ (Input.GetKey(KeyCode.S) ? -1 : 0) + (Input.GetKey(KeyCode.W) ? 1 : 0);
// 2. 构建移动方向向量(基于世界坐标系的X/Z平面,Y轴不变避免上下移动)
Vector3 moveDirection = new Vector3(horizontalInput, 0f, verticalInput);