47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class TestScript : MonoBehaviour
|
|
{
|
|
private Rigidbody _rigidbody;
|
|
private InputAction _moveAction;
|
|
private InputAction _attackAction;
|
|
|
|
[SerializeField]
|
|
private float torqueForce;
|
|
|
|
private void Awake()
|
|
{
|
|
_rigidbody = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_moveAction = InputSystem.actions.FindAction("Move");
|
|
_attackAction = InputSystem.actions.FindAction("Attack");
|
|
|
|
_moveAction.Enable();
|
|
_attackAction.Enable();
|
|
|
|
Debug.Log(_moveAction);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var moveValue = _moveAction.ReadValue<Vector2>();
|
|
|
|
Debug.Log(moveValue);
|
|
|
|
Debug.Log(_attackAction.IsPressed());
|
|
|
|
_rigidbody.AddTorque(new Vector3(0, 0, -moveValue.normalized.x) * torqueForce);
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
var moveValue = _moveAction.ReadValue<Vector2>();
|
|
|
|
_rigidbody.AddTorque(new Vector3(0, 0, moveValue.normalized.x) * torqueForce);
|
|
}
|
|
}
|