- Home /
show variable number in gui box?
so i have a GUI box and it says "Current Money" and inside that i want the to show how much my Money variable has
heres the code :
var CurrentMoney : float = 20;
var MoneyGUI : GUI;
var Rigid50 : GameObject;
var Rigid100 : GameObject;
var Rigid150 : GameObject; // these are just for the rigidbody , so when i kill the rigidbody attached to this i get 150 money
function Update (){
if(CurrentMoney < 0){
CurrentMoney = 0;
}
}
function OnGUI (){
GUI.Box (Rect (10,10,100,90), "Current Money");
if (GUI.Box(Rect (20,40,80,20), CurrentMoney)) { // THIS LINE
}
}
Answer by robertbu · Dec 18, 2013 at 01:26 AM
GUI.Box() is not a button and therefore does not use an 'if' statement. Try this:
function OnGUI (){
GUI.Box (Rect (10,10,100,90), "Current Money");
GUI.Box(Rect (20,40,80,20), CurrentMoney.ToString());
}
It will depend on what game object the money script is attached to and what you need to do to get access. Here is general information:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
If you are still stuck after reading this, post a new question. Include specifics about where the $$anonymous$$oneyScript is attached, and the name of the variable that keeps the score.
Oh man , you gave me a correct link everyone else was giving me dead links -___- thanks man , you are rally helpful
Answer by JSierraAKAMC · Dec 18, 2013 at 01:36 AM
Or, you could do as I do:
function OnGUI()
{
GUI.Box(Rect(10,10,100,90), "Current Money");
GUI.Box(Rect(20,40,80,20), "" + CurrentMoney);
}
Answer by marcell123455 · Nov 13, 2015 at 09:53 PM
How could i add money to the CurrentMoney variable from a other script?
var target : GameObject;
function start () {
target.CurrentMoney = + 30;
}
or what? :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613124405im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you add a fixed joint to a first person controller 1 Answer
How to do Switching Weapon System 1 Answer
how to change scene using rigidbody 3 Answers
how to get a buy menu? 0 Answers
Object Collider problem, objects going through walls? 1 Answer