Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 faestae · Sep 10, 2014 at 10:24 AM · c#javascriptguitextureguitexttimer countdown

Pairing and GUITexture with a Timer?

Hello! I am working on a project that currently uses a timer that counts down from any number as a GUIText object.

While that is all fine and dandy (and it works), I was wondering how I would achieve this with a GUITexture so I can have something a little more visual. It would be a gauge that sits at the top of the screen, and as time passes, the gauge will go down until its gone, and when its gone, the game will end.

The only issue I can think of is, the way the timer works in my game, time is added and taken away over the course of the game, does this mean in order for this to work, I'll need a cap on the time allowed? If so, how will that affect the solution to my problem

(I am relatively new to code, but know basics of C# and less Java)

Thanks in advance!!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VesuvianPrime · Sep 10, 2014 at 12:12 PM

There are a lot of different ways you can accomplish this. There are packages like NGUI that have builtin functionality for "filled" sprites that are perfect for health bars.

If you want to roll your own, the method I have adopted in the past:

  1. Read up on creating procedural meshes: http://blog.nobel-joergensen.com/2010/12/25/procedural-generated-mesh-in-unity/

  2. Create a simple mesh plane.

  3. Assign your material to the plane, make sure the UVs are correct.

  4. Write a method so you can set a float value between 0.0f and 1.0f to resize the mesh plane.

  5. When the float value changes, adjust your UVs accordingly. This will make sure any texturing does not become squashed, but instead is sliced.

Your last question is related to point 4: you need a way to convert your time into a 0.0f to 1.0f range. If values can exceed 1.0f (100% fill) I'm wondering if a texture representation is a good idea?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Replacing letters with images? 1 Answer

Android: How do you position GUITexture and GUIText according to different screen sizes (JS)? 2 Answers

How to Show / Hide a GUI Texture 1 Answer

Clicking stops working when viewing WebPlayer games 0 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