- Home /
show entered amount gui/label
how would i make the entered values show up in a gui/label? can anyone help please?
var information: String;
private var guiOn = false;
private var rect: Rect;
var btnTexture : Texture;
var ClosePostion : Vector2 = new Vector2 (200,5);
var CloseSize : Vector2 = new Vector2 (35,35);
var CloseIcon : Texture;
var MyString = "";
//click to open gui
function OnMouseDown(){
guiOn = true;
rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
yield WaitForSeconds(500);
guiOn = false;
}
function OnGUI(){
if (guiOn){
GUI.Box(Rect(0,0,200,200),"Current bid");
if (!btnTexture) {
Debug.LogError("Assign a texture");
return;
}
if (GUI.Button(Rect(10,10,50,50),btnTexture))
Debug.Log("texturebutton");
if (GUI.Button(Rect(10,70,50,30),"Bid")) {
var bid : int;
if (!int.TryParse(MyString, bid))
bid = 0;
Debug.Log("The bid was: "+bid);
}
var temp = "";
for (var c : char in MyString) {
if (c >= "0"[0] && c <= "9"[0]) {
temp += c;
}
}
MyString = temp;
MyString = GUI.TextField(new Rect(10,130,180,20),MyString,30);
//close button
if (GUI.Button(Rect(160,2,CloseSize.x,CloseSize.y),CloseIcon)) {
guiOn = false;
}
}
}
Answer by cdrandin · Aug 07, 2013 at 02:23 AM
If that works I am surprised.
MyString = temp;
MyString = GUI.TextField(new Rect(10,130,180,20),MyString,30);
Should not work since yo are overwriting the type.
But simply when you fix it. Just change your string when ever you can. To do this you would want to use Unity's Update() function and change to whenever you want it to on a given key pressed or whatever.
yeah it works, still really confused as to how to show the input value that gets entered in the textfield
ok try this
create an Update function. In it do this bid += 1
then see what happens with your GUI display of your bid. It should change.
try this out. http://shrib.com/$$anonymous$$6$$anonymous$$ItGjY copy and paste should work
ok, what are they? Can you not resolve them? They are probably bad syntax.
Answer by cdrandin · Aug 07, 2013 at 03:40 AM
ok I changed your code because most of it made no sense and the for loop was just completely wrong.
#pragma strict
var information: String;
private var guiOn = false;
private var rect: Rect;
var btnTexture : Texture;
var ClosePostion : Vector2 = new Vector2 (200,5);
var CloseSize : Vector2 = new Vector2 (35,35);
var CloseIcon : Texture;
var MyString = "";
var bid : int;
function Start ()
{
bid = 0;
}
function Update ()
{
bid += 1;
if(Input.GetMouseButtonDown(1))
{
guiOn = !guiOn;
Debug.Log("Pressed right click.");
}
}
function OnGUI()
{
if (guiOn)
{
GUI.Box(Rect(0,0,200,200),"Current bid: " + bid.ToString());
if (!btnTexture)
{
Debug.LogError("Assign a texture");
return;
}
}
}
If you really want to use your other code. Please look over the GUI documentation. You are doing displays poorly.
ive just tried this code and and the bid amount goes up automatically and i cant place a bid, any ideas?
I told you a removed all that stuff. Add in your old code block by block, don't paste it all there.
Also, you keep putting extra '}' so careful with your syntax. Also, don't just blindly do stuff. Have reason for why it should be there. I won't be able to reply anymore. I have to study now. Good luck. Like I said think about why you are writing that code and what you are trying to achieve.
Your answer
Follow this Question
Related Questions
OnGUI called after LateUpdate screwing up debug text database 1 Answer
GUI.Label font size scale - using GUISkin 1 Answer
Score display not working 1 Answer
Player label appears in sky! 0 Answers
GUI label on raycast? 0 Answers