GUI control to accept INTEGERS

Am I just missing something or is a GUI control to accept integer input from players Not available.

I’m writing some code that needs to be in c# and I want to give the user an option to change an integer value.

But all I’m finding is GUI.TextField which only takes stings. Then the Unity editor is tell me I can’t type cast this to an int. :frowning:

Use parseInt().

–Eric

That converts after the fact but if you have this:

public static int serverPort = 56882;

// Temp variable to hold User Input
	
string tempPort;

tempPort = GUI.TextField(new Rect(100, 136, 200, 20), " " + (serverPort), 25);

// Need to make sure this is the proper method *****
serverPort = (int) int.Parse(tempPort);

You get errors when you actually run it. :frowning:

What errors are you getting exactly?

If the text area contains a non-integer, or is blank, then int.Parse will have a problem, but you can check the value of tempPort before trying to parse it.

It works after reboot. :slight_smile:

I have to say Unity seems to have issues with c#.
I never had any weirdness with Java coding. But I have had skins fail for no reason and had to reboot twice during c# coding.

Any idea how to handle this in JS? I’m trying to do the same thing with JS and failing. I want to have a player input a number between 1 and 100 and have it only accept numbers that are then converted to an int.