Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class KonamiCode : MonoBehaviour
- {
- private List<string> inputSequence = new List<string>();
- private readonly string[] konamiCode =
- {
- "Up", "Up", "Down", "Down",
- "Left", "Right", "Left", "Right",
- "B", "A", "B", "A", "Start"
- };
- public InputActionAsset inputActions;
- private InputActionMap actionMap;
- private Dictionary<string, InputAction> actions;
- void Start()
- {
- actionMap = inputActions.FindActionMap("Player", true);
- actions = new Dictionary<string, InputAction>();
- foreach (var action in konamiCode)
- {
- var inputAction = actionMap.FindAction(action, true);
- if (inputAction != null)
- {
- inputAction.performed += ctx => RegisterInput(action);
- actions[action] = inputAction;
- }
- }
- actionMap.Enable();
- }
- void RegisterInput(string actionName)
- {
- inputSequence.Add(actionName);
- if (inputSequence.Count > konamiCode.Length)
- {
- inputSequence.RemoveAt(0);
- }
- if (CheckKonamiCode())
- {
- ActivateCheat();
- inputSequence.Clear();
- }
- }
- bool CheckKonamiCode()
- {
- if (inputSequence.Count != konamiCode.Length) return false;
- for (int i = 0; i < konamiCode.Length; i++)
- {
- if (inputSequence[i] != konamiCode[i])
- return false;
- }
- return true;
- }
- void ActivateCheat()
- {
- Debug.Log("Konami Code Activated!");
- // Implement your cheat logic here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement