Last active
October 14, 2018 00:42
-
-
Save daltonbr/6109c385e2c94eadbcf19bcb2c8e5165 to your computer and use it in GitHub Desktop.
A decoupled Input system from Unity / C#
This file contains 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; | |
public class Input : MonoBehaviour | |
{ | |
public float Horizontal { get; private set; } | |
public float Vertical { get; private set; } | |
public bool FireWeapons { get; private set; } | |
public event Action OnFire = delegate { }; | |
private void Update() | |
{ | |
Horizontal = Input.GetAxis("Horizontal"); | |
Vertical = Input.GetAxis("Vertical"); | |
FireWeapons = Input.GetButtonDown("Fire1"); | |
if (FireWeapons) | |
{ | |
OnFire(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment