Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Septien · Feb 21, 2010 at 07:30 AM · guiiphonegraphicsoptimization

How to implement an ammo counter using textured quads? [Scripting doubts]

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)

if(ammo==24){

//show "2" on dozens counter counterA0.renderer.enabled = false; counterA1.renderer.enabled = false; counterA2.renderer.enabled = true; //quad showing "2" for dozens counterA3.renderer.enabled = false; counterA4.renderer.enabled = false; counterA5.renderer.enabled = false; counterA6.renderer.enabled = false; counterA7.renderer.enabled = false; counterA8.renderer.enabled = false; counterA9.renderer.enabled = false;

//show "4" on units counter counterB0.renderer.enabled = false; counterB1.renderer.enabled = false; counterB2.renderer.enabled = false; counterB3.renderer.enabled = false; counterB4.renderer.enabled = true; //quad showing "4" for units counterB5.renderer.enabled = false; counterB6.renderer.enabled = false; counterB7.renderer.enabled = false; counterB8.renderer.enabled = false; counterB9.renderer.enabled = false; }

Thanks in advance!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sebas · Feb 21, 2010 at 10:02 AM 0
Share

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.

avatar image Septien · Feb 21, 2010 at 10:41 AM 0
Share

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.

avatar image nonaxanon · Apr 17, 2012 at 04:37 PM 0
Share

@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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Jaap Kreijkamp · Feb 21, 2010 at 11:22 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).

var digitA = (ammo / 10) % 10; var digitB = (ammo % 10);

switch (digitA) { case 0 : counterA0.renderer.enabled = false; break; case 1 : counterA1.renderer.enabled = false; break; case 2 : counterA2.renderer.enabled = false; break; case 3 : counterA3.renderer.enabled = false; break; case 4 : counterA4.renderer.enabled = false; break; case 5 : counterA5.renderer.enabled = false; break; case 6 : counterA6.renderer.enabled = false; break; case 7 : counterA7.renderer.enabled = false; break; case 8 : counterA8.renderer.enabled = false; break; case 9 : counterA9.renderer.enabled = false; break; }

switch (digitB) { case 0 : counterB0.renderer.enabled = false; break; case 1 : counterB1.renderer.enabled = false; break; case 2 : counterB2.renderer.enabled = false; break; case 3 : counterB3.renderer.enabled = false; break; case 4 : counterB4.renderer.enabled = false; break; case 5 : counterB5.renderer.enabled = false; break; case 6 : counterB6.renderer.enabled = false; break; case 7 : counterB7.renderer.enabled = false; break; case 8 : counterB8.renderer.enabled = false; break; case 9 : counterB9.renderer.enabled = false; break; }

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Septien · Feb 21, 2010 at 11:46 AM 0
Share

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?

avatar image
0

Answer by thomas.du · Feb 21, 2010 at 12:57 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

What is the expected behaviour of Dynamic Batching? 2 Answers

Whats the best way to setup a screen like this... 0 Answers

Swiping images across the screen - iPhone 0 Answers

How could I create a dynamic cartoon style speech bubble? 1 Answer

Can I stop a lerp completely when it gets to 20% of its original value? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges