Question by
HappyCrayfish · Sep 26, 2015 at 07:45 PM ·
c#unity 5guistring
Developer Console problems..... (in-game console)
So, I'm trying to make an in-game developer console and I've ran into a problem... Can't really understad the error.... :P
Error :
ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
System.String.Substring (Int32 startIndex, Int32 length) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/String.cs:356)
And my code looks like this :
using UnityEngine;
using System.Collections;
public class DevConsole : MonoBehaviour {
public string devConsole;
void OnGUI() {
devConsole = GUI.TextField (new Rect (10, 100, 400, 30), devConsole);
if (Input.GetKeyUp (KeyCode.Return)) {
Debug.Log ("Return was pressed");
if (devConsole.Length > 4 && devConsole.Substring(0, 4) == "say ") {
Debug.Log (devConsole.Substring(4, devConsole.Length));
devConsole = "";
}
}
}
}
Comment