Created
February 12, 2021 16:49
-
-
Save doncabreraphone/3e4ae9f3683b8b10e15e9856b444dcb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using UnityEngine.Events; | |
using UnityEngine.InputSystem; | |
[Serializable] | |
public class MoveInputEvent : UnityEvent<float, float> { } | |
public class InputController : MonoBehaviour | |
{ | |
Controls controls; | |
public MoveInputEvent moveInputEvent; | |
private void Awake() | |
{ | |
controls = new Controls(); | |
} | |
private void OnEnable() | |
{ | |
controls.Player.Enable(); | |
controls.Player.Move.performed += OnMovePerformed; | |
controls.Player.Move.canceled += OnMovePerformed; | |
} | |
private void OnMovePerformed(InputAction.CallbackContext context) | |
{ | |
Vector2 moveInput = context.ReadValue<Vector2>(); | |
moveInputEvent.Invoke(moveInput.y, moveInput.x); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerController : MonoBehaviour | |
{ | |
public float moveSpeed = 5.0f; | |
public float turnSpeed = 50f; | |
float horizontal; | |
float vertical; | |
public void Update() | |
{ | |
Vector3 moveDirection = Vector3.forward * vertical + Vector3.right * horizontal; | |
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime); | |
} | |
public void OnMoveInput(float vertical, float horizontal) | |
{ | |
this.vertical = vertical; | |
this.horizontal = horizontal; | |
Debug.Log($"Player Controller: Move Input: {vertical}, {horizontal}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment