|
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!
(comments are locked)
|
|
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. Thanks, Jaap! I understand your point. Regarding the materials, i was using this approach since its an iphone game i just had 1 material/texture for all the quads, so they all got batched into 1 draw call. Can you just explain me how to read this part of your code? "var digitA = (ammo / 10) % 10; var digitB = (ammo % 10); " are the "%10" any kind of operators?
Feb 21 '10 at 11:46 AM
Septien
(comments are locked)
|
|
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 ;-) greetings, thomas
(comments are locked)
|

What kind of "Animation" do you need for your counter? A GUI element would make it much easier and depending on what you need exactly, this could possibly created with some GUI element.
The animation i am using for the counter is similar to a zoom-in - zoom-out. ie: when a digit changes its value, its quad does a brief animation that changes its scale from 1 to 1.5 to 1 again, then stop.
@Septien, did you got this done ? if so could you contact me , im wondering and been searching around for some time and have not found something like this, maybe its because im not using correct words on saint google, if you could please let me know