• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Replacing letters with images? 1 Answer

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

Multiple Cars not working 1 Answer

How to Show / Hide a GUI Texture 1 Answer

Distribute terrain in zones 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges