User input

How hard it will be to create a control where the user can input some data ? I think it’s called TextBox on almost every visual language.

Where should i look or right now it can be done only with 100% scripting ?

If so… im going to script it as soon as possible ;D

Omar Rojo

Yep, go for the scripting.

–Eric

There is a starting point for this called like EditableGUIText.js in the “Old: Script Examples” http://unity3d.com/examples/

Making a Mac OS X like text field is really hard in Unity right now, but doable with some hacks for scrolling.

Cheers,
-Jon

This may cause more confusion than help - but its a simple JS to grab user input - just drop it on a GUIText object.

WARNING: you have to modify the script - its not ‘plug n play’ :wink:

anyway… hope it gives you a general idea

//If we click on the textbox, allow input
function OnMouseUp () {
	System_Globals.instance.ClearUserName();
	System_Globals.intTABCurrent = 1;
}

function Update () {
//If Grabinput is on, then capture keystrokes
if(System_Globals.intTABCurrent==1){
	System_Globals.instance.ClearUserName();    

    for (var c : char in Input.inputString) {
        // Backspace - Remove the last character
        if (c == "\b") {
            if (guiText.text.Length != 0)
                guiText.text = guiText.text.Substring(0, guiText.text.Length - 1);
        }
        // End of entry
        else if (c == "\n") {
            System_Globals.intTABCurrent = 0;
        }
		// Pressed TAB key - do nothing
        else if (c == "\t") {
        }
        // Normal text input - just append to the end
        else 
        {
        	var intr : Rect;
    		intr = guiElement.GetScreenRect();
			//if the text will overflow the textbox, ignore user input
			if(intr.width < 100){
            guiText.text += c;
            }
    	}
	}
}
}

ps. I had a global script holding the Tab control variables, plus a background textbox GUITexture that would enable text input when enabled.