- Home /
How to create an adaptive Can Counter?
I am working on an indie game and me and my team are in pre production. I am starting to put together a test build for testing the game mechanics. I have a question regarding the GUI: How to create an adaptive Can Counter?
When players collect an inventory item e.g spray can, it goes towards their can count. On the top of the screen are several things: The Spray can icon and the can counter icon.
-Spray Can Icon: When players have no spray cans, the icon is red. When they press the key bind to using a spray can, the red spray can icon shakes and an error noise is triggered. When a player has 1 or more cans and is below their capacity limit, the can icon is yellow. When players collect cans and reach their capacity limit, they can no longer collect any cans. The spray can icon is green when the limit is reached.
-Can Counter icon: is positioned next to the spray can icon e.g x12 or x1. It shows the number of cans in the player's collection. the counter does not get any higher in numbers once the can capacity limit is reached.
Simon,
Looking back at your question list, and the follow up you asked from SpinalJack's answer, you might benefit from spending some time with the tutorials from Unity's site.
Also, check out this amazing list of tutorials at: http://answers.unity3d.com/questions/4897/how-can-i-start-learning-unity-fast
Answer by spinaljack · Jun 11, 2010 at 01:40 PM
You need a variable called cans and you just output the integer in a GUI.label e.g.
var cans : int = 0; var maxCans : int = 15;
funtion OnGUI(){ GUI.Label(Rect(someRect),"Cans X " + cans, yourGUIStyle); }
To limit your total cans just add an if statement:
function AddCans(number int){
if(cans+number<maxCans){
cans+=number;
}else{
cans = maxCans;
}
}
Unity GUI documents:
http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html
Thanks spinaljack, now I need to know how to make the 'GUI Label' I think thats making the icons adapt to the amount of cans?
Your answer
Follow this Question
Related Questions
Shot Counter Question 2 Answers
Little image next to GUI ? 1 Answer
Gui Counter Problem 1 Answer
Score counter out of control, help needed. 1 Answer
GUI ammo counter not linked to player 0 Answers