- Home /
How to put strings in a gui?
var MouseEnter : System.Boolean; var Name : String; var Level : String; var Damage : String; var Intelligence : String;
function OnMouseEnter() { MouseEnter = true; }
function OnMouseExit() { MouseEnter = false; }
function OnGUI() { if(MouseEnter == true) {
GUI.Box(Rect(200,100,150,200),Name); GUI.Label(Rect(205,150,100,100),"Level : ",Level); GUI.Label(Rect(205,200,100,100),"Damage : ",Damage); GUI.Label(Rect(205,250,100,100),"Intelligence : ",Intelligence);
}
}
here is my script how ever when it runs it says "Unable to find style '1' in skin 'GameSkin' repaint" but im just wanting the string that i type in the editor to pop up please help thanx :)
Format code by selecting it and hitting the code format button.
Answer by Eric5h5 · Jul 27, 2010 at 02:16 AM
You're trying to use string variables as GUIStyle parameters. Change the "," to a "+":
GUI.Label(Rect(205,150,100,100),"Level : "+Level);
BTW, you can just use "boolean" instead of "System.Boolean". Also it's a good idea to get in the habit of using lowercase for variable names (and upper case for functions and classes), because that's what the convention is in Unity, so code that adheres to that is more understandable. Also you should use appropriate types for variables...the level, damage, and intelligence variables should probably be ints, and then use ToString() to convert to strings where necessary.
Perhaps you could add the ToString() to your code snippet to make it more clear that it is important to include, and and how to use it? :)