51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace ECM2.Examples.Jump
|
|
{
|
|
public class CharacterInput : MonoBehaviour
|
|
{
|
|
private Character _character;
|
|
|
|
private JumpAbility _jumpAbility;
|
|
|
|
private void Awake()
|
|
{
|
|
_character = GetComponent<Character>();
|
|
_jumpAbility = GetComponent<JumpAbility>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
Vector2 vector = new Vector2
|
|
{
|
|
x = Input.GetAxisRaw("Horizontal"),
|
|
y = Input.GetAxisRaw("Vertical")
|
|
};
|
|
Vector3 vector2 = Vector3.zero;
|
|
vector2 += Vector3.right * vector.x;
|
|
vector2 += Vector3.forward * vector.y;
|
|
if ((bool)_character.camera)
|
|
{
|
|
vector2 = vector2.relativeTo(_character.cameraTransform);
|
|
}
|
|
_character.SetMovementDirection(vector2);
|
|
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.C))
|
|
{
|
|
_character.Crouch();
|
|
}
|
|
else if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.C))
|
|
{
|
|
_character.UnCrouch();
|
|
}
|
|
if (Input.GetButtonDown("Jump"))
|
|
{
|
|
_jumpAbility.Jump();
|
|
}
|
|
else if (Input.GetButtonUp("Jump"))
|
|
{
|
|
_jumpAbility.StopJumping();
|
|
}
|
|
}
|
|
}
|
|
}
|