Files
OMG/Assets/Scripts/PlayerMovement.cs

40 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
private InputMaster _inputMaster;
[SerializeField] private CharacterController controller;
[SerializeField] private float speed;
[SerializeField] private float mouseSensitivity = 20f;
[SerializeField] private Transform playerBody;
private float _mouseX, _mouseY;
private Vector2 _moveDirection;
private void Awake()
{
controller = GetComponent<CharacterController>();
_inputMaster = new InputMaster();
_inputMaster.Player.Look.Enable();
_inputMaster.Player.Move.Enable();
}
private void Update()
{
var mousevalue = _inputMaster.Player.Look.ReadValue<Vector2>();
_mouseX = mousevalue.x * mouseSensitivity * Time.deltaTime;
_mouseY = mousevalue.y * mouseSensitivity * Time.deltaTime;
playerBody.Rotate(Vector3.up * _mouseX);
}
public void OnMove(InputAction.CallbackContext context)
{
_moveDirection = context.ReadValue<Vector2>();
Debug.Log("direction: " + _moveDirection);
}
}