Integrate Input System with movement and attack actions
This commit is contained in:
@@ -1,16 +1,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class TestScript : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
private Rigidbody _rigidbody;
|
||||
private InputAction _moveAction;
|
||||
private InputAction _attackAction;
|
||||
|
||||
[SerializeField]
|
||||
private float torqueForce;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user