How to make "cheat codes"?

I want to make an Input Field, that would check what did you write in there after clicking “Enter”, for example if you have written here “give money 500”, then 500 money would be added, but how to do it?

Hmm, I have something like in my inventory system,

What you need, is your variable “money” to have an “add” function which gets passed a string.

you parse the string in your function,

so you have input field > pass its string to your function > your function parses the variables it needs out of it (i.e., if (myString.SubString(0, 3).Contains(“add”)){/do the stuff to add it/} Which I think you’ll be looking at things like TryParse to grab the number.

public InputField inputField = null;
private IDictionary<string, Action>dict ;
void Start()
{
this.dict = new DIctionary<string,Action>();
this.dict.Add(“give money 500”, AddMoneyFiveHundred);
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Return)){
CheckInput(this.inputField.value);
}
}
void CheckInput(string str)
{
if(this.dict.ContainsKey(str) == false){ return; }
this.dictstr;
}
void AddMoneyFiveHundred(){
// Get the money component
// add 500
}

You need the InputField reference so you can get the value. When user presses enter, check the content. This is simplified, you shouldactually check first if the InputField is currently used but I leave it to you.

When enter is pressed, check that the dictionary contains the key. If not, return and do nothing.
If the dictionary contains the key, call the method assigned to it.

In the Start, the dictionary is populated with string and matching action, this is again simplified as you could get the content from a file or other script. But at least, you get the idea.

Simple as this

private string[] cheatCode;
private int index;
 
 void Start() {
     // Code is "idkfa", user needs to input this in the right order
     cheatCode = new string[] { "g", "i", "v", "e", "m", "e", "m", "o", "n", "e", "y" };
     index = 0;    
 }
 
 void Update() {
     // Check if any key is pressed
     if (Input.anyKeyDown) {
         // Check if the next key in the code is pressed
         if (Input.GetKeyDown(cheatCode[index])) {
             // Add 1 to index to check the next key in the code
             index++
         }
         // Wrong key entered, we reset code typing
         else {
             index = 0;    
         }
     }
     
     // If index reaches the length of the cheatCode string, 
     // the entire code was correctly entered
     if (index == cheatCode.Length) {
         // Cheat code successfully inputted!
         // Unlock crazy cheat code stuff
     }
 }

Check this out here