blob: fd96db19910a3a064b65954eae8297457e89dd3e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}
}
|