I am trying to implement a counter who will show current ammo in an iphone game (similar to a gui item).
The approach i have been testing is by using 10 quads for each digit (0-9) who all share the same material/texture (to batch them into 1 draw call), the reason for not using a guitext or similar element is that i need a small animation on each of them, similar to a "pop-up" on each digit everytime the counter changes its value.
Example: Lets imagine the maximum ammo i can have at any given time is 99. For this i have a setup of 10 quads for the the first units digit and another 10 quads for the dozens digit. All of them have the renderer disabled, except for the ones who actually show the digits i want.
My doubt: I want to collect an integer variable that represents the current ammo (ie: 24) and separate it into "2" and "4", so that my quad group representing the dozens turns on the renderer showing "2" and the other group shows "4".
Anyone can point me in what to research, or any example of a correct approach? My current code test (limited by scripting knowledge) will soon become a mess Sad (imagine this for 100 cases lol)
Thanks in advance!
asked Feb 21 '10 at 07:30 AM
The solution I give is far from a good one, but it uses the counterA/B0-9 as you've defined and should be easy to understand (works from 0 .. 99 but it should be easy to add a digit).
As I said, this works, with the setup you have now, and maybe for now you should leave it by that until you've learned more about unity and scripting. To give you a lead to a better solution:
Instead to have for every possible value per digit another gameobject a simple optimization would be to have 10 different materials each with another digit and just change the material for the digit gameobject. If you put the 10 materials into an array you can just change the material using the calculated digit (digitA or digitB vars) as index instead of using those long switch statements.
answered Feb 21 '10 at 11:22 AM
what about changing the texture?
like from the docs:
var someTexture : Texture2D; guiTexture.texture = someTexture;
so, define 10 texture for each digit and swap the texture of the tenth and the, well other digit dont know how its called in english ;-)
answered Feb 21 '10 at 12:57 PM