Advertisement
Guest User

konami code

a guest
Feb 28th, 2025
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.InputSystem;
  4.  
  5. public class KonamiCode : MonoBehaviour
  6. {
  7. private List<string> inputSequence = new List<string>();
  8. private readonly string[] konamiCode =
  9. {
  10. "Up", "Up", "Down", "Down",
  11. "Left", "Right", "Left", "Right",
  12. "B", "A", "B", "A", "Start"
  13. };
  14.  
  15. public InputActionAsset inputActions;
  16. private InputActionMap actionMap;
  17. private Dictionary<string, InputAction> actions;
  18.  
  19. void Start()
  20. {
  21. actionMap = inputActions.FindActionMap("Player", true);
  22. actions = new Dictionary<string, InputAction>();
  23.  
  24. foreach (var action in konamiCode)
  25. {
  26. var inputAction = actionMap.FindAction(action, true);
  27. if (inputAction != null)
  28. {
  29. inputAction.performed += ctx => RegisterInput(action);
  30. actions[action] = inputAction;
  31. }
  32. }
  33.  
  34. actionMap.Enable();
  35. }
  36.  
  37. void RegisterInput(string actionName)
  38. {
  39. inputSequence.Add(actionName);
  40.  
  41. if (inputSequence.Count > konamiCode.Length)
  42. {
  43. inputSequence.RemoveAt(0);
  44. }
  45.  
  46. if (CheckKonamiCode())
  47. {
  48. ActivateCheat();
  49. inputSequence.Clear();
  50. }
  51. }
  52.  
  53. bool CheckKonamiCode()
  54. {
  55. if (inputSequence.Count != konamiCode.Length) return false;
  56.  
  57. for (int i = 0; i < konamiCode.Length; i++)
  58. {
  59. if (inputSequence[i] != konamiCode[i])
  60. return false;
  61. }
  62. return true;
  63. }
  64.  
  65. void ActivateCheat()
  66. {
  67. Debug.Log("Konami Code Activated!");
  68. // Implement your cheat logic here
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement