Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Created March 11, 2015 09:49
Show Gist options
  • Save paulhayes/11daa42afd470c6bc75e to your computer and use it in GitHub Desktop.
Save paulhayes/11daa42afd470c6bc75e to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
public class CheatCode : MonoBehaviour
{
public string code;
public UnityEvent onCodeEntered;
protected int current;
void Update()
{
if (Input.anyKeyDown) {
if (Input.GetKeyDown(code [current].ToString())) {
current++;
if (current >= code.Length) {
current = 0;
onCodeEntered.Invoke();
}
} else {
current = 0;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment