- Home /
Storing and displaying info from textfield
How would i store and display information that has been entered in to a textfield?
#pragma strict
private var rect: Rect;
var btnTexture : Texture;
private var guiOn = false;
var ClosePostion : Vector2 = new Vector2 (200,5);
var CloseSize : Vector2 = new Vector2 (35,35);
var CloseIcon : Texture;
var bid : String = "";
var bidPostion : Vector2 = new Vector2(200,30);
var bidSize : Vector2 = new Vector2 (50,30);
function Start () {
}
function Update () {
}
//opens gui
function OnMouseDown()
{
guiOn = true;
rect = Rect(Input.mousePosition.x,Input.mousePosition.y,300,100);
yield WaitForSeconds(100);
guiOn = false;
}
//gui to display
function OnGUI(){
if (guiOn){
GUI.Box(Rect(0,0,200,200),"bids");
if(!btnTexture){
Debug.LogError("assign a texture");
return;
}
//close button
if (GUI.Button(Rect(ClosePostion.x,ClosePostion.y,CloseSize.x,CloseSize.y),CloseIcon)) {
guiOn = false;
//bid Textfield
}
bid = GUI.TextField (Rect (bidPostion.x, bidPostion.y, bidSize.x, bidSize.y), bid, 25);
}
}
Comment
Answer by robertbu · Aug 15, 2013 at 07:20 AM
I'm not sure what you are going for in this question, but here is some modified code. It move the bid amount to 'previousBid' and displays that amount when the close button is clicked:
#pragma strict
private var rect: Rect;
var btnTexture : Texture;
private var guiOn = false;
var ClosePostion : Vector2 = new Vector2 (200,5);
var CloseSize : Vector2 = new Vector2 (35,35);
var CloseIcon : Texture;
var bid : String = "";
var bidPostion : Vector2 = new Vector2(200,30);
var bidSize : Vector2 = new Vector2 (50,30);
var previousBid = "";
var showPrevBid = false;
//opens gui
function OnMouseDown() {
guiOn = true;
rect = Rect(Input.mousePosition.x,Input.mousePosition.y,300,100);
yield WaitForSeconds(100);
guiOn = false;
}
//gui to display
function OnGUI(){
if (guiOn){
GUI.Box(Rect(0,0,200,200),"bids");
if(!btnTexture){
Debug.LogError("assign a texture");
return;
}
//close button
if (GUI.Button(Rect(ClosePostion.x,ClosePostion.y,CloseSize.x,CloseSize.y),CloseIcon)) {
guiOn = false;
previousBid = bid;
showPrevBid = true;
}
bid = GUI.TextField (Rect (bidPostion.x, bidPostion.y, bidSize.x, bidSize.y), bid, 25);
}
if (showPrevBid) {
GUI.Label(Rect(30,300,100,50), previousBid);
}
}
Your answer
Follow this Question
Related Questions
iOS Keyboard makes performance suffer 3 Answers
GUI.TextField 1 Answer
Cannot type in textfield in Chrome on Mac 0 Answers
Check if string contains letters 1 Answer