Help with making cheat engine

I’m trying to make a sort of developer’s console thing that lets me add values while in-game and stuff. I can get it to open, but once it does open it just creates an endless stream of spaces and zeroes.
Additionally, I can only open it with GetButton because it won’t open at all if I use GetButtonDown.

Here’s the script:

using UnityEngine;
using System.Collections;

public class DevConsole : MonoBehaviour {

	private bool IsConsoleOpen;
	string Cmd1, Cmd2;
	string CommandInput (string Command, int AddedValue)
	{
		return string.Format ("{0} {1}", Command, AddedValue);
	}
	public string InputCmd;
	public int CmdVal;

	// Use this for initialization
	void Start () {
		Cmd1 = "addrings";
		Cmd2 = "addlives";
		IsConsoleOpen = false;
	
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetButton ("Open Console") && !IsConsoleOpen)
		{
			IsConsoleOpen = true;
			Time.timeScale = 0;
		}
		else if (Input.GetButton ("Open Console") && IsConsoleOpen)
		{
			IsConsoleOpen = false;
			Time.timeScale = 1;
		}
	
	}
	void OnGUI()
	{
		if (IsConsoleOpen)
		{
			InputCmd = GUI.TextField (new Rect (Screen.width / 2 - 200, Screen.height - 150, 400, 30), CommandInput (InputCmd, CmdVal));
			if (GUI.Button (new Rect (Screen.width / 2 - 35, Screen.height - 115, 70, 30), "Submit"))
			{
				if (InputCmd == Cmd1)
				{
					gameObject.GetComponent<StockManager>().TotalRings += CmdVal;
				}
				else if (InputCmd == Cmd2)
				{
					gameObject.GetComponent<StockManager>().TotalStock += CmdVal;
				}
				else if (InputCmd != Cmd1 && InputCmd != Cmd2)
				{
					IsConsoleOpen = false;
				}
			}
		}
	}
}

The reason why you get this endless steam of 0’s. Is because you are adding these at line 41…

Sinse this code is called multiple times per frame when (IsConsoleOpen == true). Sinse you are probably running at at least 60 frames per second, at least 120 zero’s are added each second.

InputCmd = GUI.TextField (new Rect (Screen.width / 2 - 200, Screen.height - 150, 400, 30), CommandInput (InputCmd, CmdVal));

What you basically say here is:

InputCmd = string.Format("{0} {1}", InputCmd, CmdVal);

// Which is the same as

InputCmd = string.Format("{0} {1}", InputCmd, "0"); // Sinse CmdVal is 0 by default

// Which is the same as

InputCmd = InputCmd + " " + "0";

The keys the user pressed are added aswell ofcource, but because the amount of 0’s added each sec, it will probably be hard to notice :smiley:

As for GetButtonDown… This should work in your current setup I believe. (Better then Input.GetButton at least, because this should result into switching between states each frame while you hold down your “Open Console” button).