using UnityEngine; using System.Text; public class ConsoleCommand : MonoBehaviour {…
- User
using UnityEngine; using System.Text;
public class ConsoleCommand : MonoBehaviour { private string consoleText = ""; private bool showConsole = false; private PlayerVitals playerVitals; private string commandOutput = "";
private string[] commands = { "heal", "list" }; private void Start() { playerVitals = FindObjectOfType(typeof(PlayerVitals)) as PlayerVitals; } private void OnGUI() { if (showConsole) { float windowWidth = 400; float windowHeight = 200; float leftPos = (Screen.width - windowWidth) / 2; float topPos = (Screen.height - windowHeight) / 2; GUI.Box(new Rect(leftPos, topPos, windowWidth, windowHeight), ""); GUI.backgroundColor = Color.black; float textFieldHeight = 20f; float textFieldTopPos = topPos + windowHeight - textFieldHeight - 10f; consoleText = GUI.TextField(new Rect(leftPos + 10f, textFieldTopPos, windowWidth - 20f, textFieldHeight), consoleText); GUI.Label(new Rect(leftPos + 10f, topPos + 5f, windowWidth - 20f, windowHeight - 30f), commandOutput); if (Event.current.isKey && Event.current.keyCode == KeyCode.Return) { if (consoleText == "heal") { Heal(); } else if (consoleText == "list") { ListCommands(); } consoleText = ""; } } } private void Update() { if (Input.GetKeyDown(KeyCode.BackQuote)) { showConsole = !showConsole; consoleText = ""; commandOutput = ""; } } private void Heal() { playerVitals.currentHealth += 100; } private void ListCommands() { StringBuilder sb = new StringBuilder(); foreach (string command in commands) { sb.AppendLine(command); } commandOutput = sb.ToString(); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.