35 lines
950 B
C#
35 lines
950 B
C#
using Scampz.GameJam.Assets.Scripts.Player;
|
|
using UnityEngine;
|
|
|
|
namespace Scampz.GameJam.Assets.Scripts
|
|
{
|
|
public class CharacterInputController : MonoBehaviour
|
|
{
|
|
private CharacterController _controller;
|
|
public float Speed = 10f;
|
|
public float RotateSpeed = 720.0f;
|
|
private PlayerState _playerState;
|
|
|
|
private void Start()
|
|
{
|
|
_controller = GetComponent<CharacterController>();
|
|
_playerState = GetComponent<PlayerState>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
var direction = new Vector3(Input.GetAxisRaw(InputOptions.Horizontal), 0, Input.GetAxisRaw(InputOptions.Vertical)).normalized;
|
|
|
|
if (_playerState.CanMove)
|
|
_controller.SimpleMove(-direction * Speed);
|
|
|
|
if (direction != Vector3.zero)
|
|
{
|
|
var toRotation = Quaternion.LookRotation(-direction, Vector3.up);
|
|
|
|
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, RotateSpeed);
|
|
}
|
|
}
|
|
}
|
|
}
|