Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Recharging value?

Discussion in 'Scripting' started by Deleted User, Dec 7, 2010.

  1. Deleted User

    Deleted User

    Guest

    Hello. How can I have a value that increases by a set amount each set interval of time until it reaches a maximum (its for a recharging power meter)? Also, how can I have each value correspond to a GUI texture (so I can actually show the player how long until the power is recharged)? Thanks.
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    The first problem is a simple program logic issue. There are multiple ways you could solve it; you could use a coroutine, or use InvokeRepeating(), or simply keep track of elapsed time in your Update() function and increase the amount at regular intervals. For restricting the value to some maximum, you can use Mathf.Clamp().

    If you need more specific help than that, post the code you have so far so we can take a look at it.

    For the second problem, try searching here and on Unity Answers for 'health bar' (as it's basically the same problem, and the topic has been discussed before).