- Home /
Make a coin add to a GUI BOX
I have a Gui script that just makes a box a says "0 coin(s)" I want it so if you collect 1 of the coins it adds 1. I made it so that if you collect the first coin it will say "1 coin(s)" and I did it with the other coin so it says 2 coins. But if the player collects them in a different order, he/she will end up with 2 coins at first then 1 coin.
Answer by MarkFinn · Nov 25, 2013 at 10:38 PM
You need to look at how variables work.
First, give your player an integer variable called CountCoins. Set it to 0.
Then, set your GUI Script to use the text
"Coins :"+player.CountCoins
instead of just text.
Now, instead of changing the gui text when you hit a coin, change the value of Player.CountCoins to increase it by 1.
player.CountCoins=player.CountCoins+1;
You will need to change this a little bit to make it work, depending on how your other scripts are set up, but learning to use variables like this is the most important first step in coding.
Yes I was going to use a variable but it didn't end up working. I know the reason now and I'm adding some of your script in. Thank you very much for the scripts :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613122801im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# Script issue with Player 1 Answer
Integration of Unity whithin GUI (ex QT) 2 Answers
GUI works flawlessly in editor, but will not show in standalone build. 1 Answer
player picture 2 Answers
Draw GUI in world space. 2 Answers