49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System.Numerics;
|
|
using TreeEditor;
|
|
using UnityEngine;
|
|
using Quaternion = UnityEngine.Quaternion;
|
|
using Vector3 = UnityEngine.Vector3;
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
float _speed = 10.0f;
|
|
|
|
void Start()
|
|
{
|
|
Managers.Input.KeytAction -= OnKyeboard;
|
|
Managers.Input.KeytAction += OnKyeboard;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
void OnKyeboard()
|
|
{
|
|
if (Input.GetKey(KeyCode.W))
|
|
{
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Vector3.forward), 0.2f);
|
|
transform.position += (Vector3.forward * Time.deltaTime * _speed);
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.S))
|
|
{
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Vector3.back), 0.2f);
|
|
transform.position += (Vector3.back * Time.deltaTime * _speed);
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.A))
|
|
{
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Vector3.left), 0.2f);
|
|
transform.position += (Vector3.left * Time.deltaTime * _speed);
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.D))
|
|
{
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Vector3.right), 0.2f);
|
|
transform.position += (Vector3.right * Time.deltaTime * _speed);
|
|
}
|
|
}
|
|
}
|