diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-30 23:07:07 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-30 23:07:07 +0800 |
| commit | bdd0c3eee905c5dc6fcf22344f7fdbd4cc3e3a02 (patch) | |
| tree | 2a8fb0c76b134890aa61dcc9e9949cedab055f57 /Assets/Scripts/SimpleControl.cs | |
| parent | b0642164b112508bbfc0b60553586ea260a79d2e (diff) | |
完成双角色操纵
Diffstat (limited to 'Assets/Scripts/SimpleControl.cs')
| -rw-r--r-- | Assets/Scripts/SimpleControl.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Assets/Scripts/SimpleControl.cs b/Assets/Scripts/SimpleControl.cs new file mode 100644 index 0000000..fd96db1 --- /dev/null +++ b/Assets/Scripts/SimpleControl.cs @@ -0,0 +1,35 @@ +using System; +using UnityEngine; + +[RequireComponent(typeof(PlayerControl))] +public class SimpleControl : MonoBehaviour +{ + private PlayerControl _playerControl; + + [Header("Parameter")] + public KeyCode moveLeft = KeyCode.A; + public KeyCode moveRight = KeyCode.D; + public KeyCode moveUp = KeyCode.W; + public KeyCode moveDown = KeyCode.S; + public KeyCode grab = KeyCode.G; + + private float HorizontalAxis => + (Input.GetKey(moveLeft) ? -1 : 0) + + (Input.GetKey(moveRight) ? 1 : 0); + + private float VerticalAxis => + (Input.GetKey(moveDown) ? -1 : 0) + + (Input.GetKey(moveUp) ? 1 : 0); + + private void Awake() + { + _playerControl = GetComponent<PlayerControl>(); + } + + private void Update() + { + _playerControl.movementHorizontal = HorizontalAxis; + _playerControl.movementVertical = VerticalAxis; + _playerControl.grabbing = Input.GetKey(grab); + } +} |
