- Home /
convert GUI.tooltip to int
im trying to convert GUI.tooltip to a int
GUI.Button(new Rect(50, Screen.height - 80, 80, 30), new GUIContent("Unit 1", "0"));
GUI.Button(new Rect(140,Screen.height - 80, 80, 30), new GUIContent("Unit 2", "1"));
GUI.Button(new Rect(230,Screen.height - 80, 80, 30), new GUIContent("Unit 3", "2"));
GUI.Button(new Rect(320,Screen.height - 80, 80, 30), new GUIContent("Unit 4", "3"));
selectedUnit = System.Int32.Parse(GUI.tooltip); //dosent work
Debug.Log(selectedUnit);
Debug.Log(System.Int32.Parse("123")); // this work
gives this error: FormatException: Input string was not in the correct format System.Int32.Parse (System.String s) Playerr.OnGUI () (at Assets/Script/Playerr.cs:165)
Comment
Best Answer
Answer by SirGive · May 29, 2011 at 06:49 AM
if (GUI.tooltip != "" )
{
selectedUnit = System.Int32.Parse(GUI.tooltip);
Debug.Log("test" + selectedUnit);
}
You don't want to set a nonexistent value. Check to make sure that GUI.tooltip actually is a valid value and if it is, then set selectedUnit to it.
I updated it a few times. Try now. With the if condition. Worked perfectly for me.