Skip to content

Instantly share code, notes, and snippets.

@daltonbr
Last active October 14, 2018 00:42
Show Gist options
  • Save daltonbr/6109c385e2c94eadbcf19bcb2c8e5165 to your computer and use it in GitHub Desktop.
Save daltonbr/6109c385e2c94eadbcf19bcb2c8e5165 to your computer and use it in GitHub Desktop.
A decoupled Input system from Unity / C#
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