Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Health Regeneration?

Discussion in 'Scripting' started by SilverFoxMedia, Nov 7, 2009.

  1. SilverFoxMedia

    SilverFoxMedia

    Joined:
    Nov 7, 2009
    Posts:
    153
    I was wondering if anyone could help me out with this.

    I want the player character to slowly regenerate lost hit points (health) over time, I'm currently using the FPSPlayer script from the FPS tutorial, if someone could point me towards how to do this, it would be much appreciated.

    Thanks.
     
  2. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Posts:
    1,224
    I haven't done the FPS tutorial, but you can try to figure out what variable contains health, and add a tiny amount each update call.

    Something like:

    Code (csharp):
    1. function Update(){
    2.     if (health < maxHealth){
    3.         health += .001 * Time.deltaTime;
    4.         if (health > maxHealth) health = maxHealth;
    5.     }
    6. }
     
  3. SilverFoxMedia

    SilverFoxMedia

    Joined:
    Nov 7, 2009
    Posts:
    153
    Cheers, I'll play around with it and see what I can do :D
     
  4. xxxhackaxxx

    xxxhackaxxx

    Joined:
    Sep 29, 2009
    Posts:
    8
    if you are using the FPSPlayer this is what you should have.

    Code (csharp):
    1. function Update(){
    2.     if (hitPoints < maximumHitPoints){
    3.         hitPoints += .4 * Time.deltaTime;
    4.         if (hitPoints > maximumHitPoints) hitPoints = maximumHitPoints;
    5.     }
    6. }
    you can change the .4 to what ever value you would like.
     
  5. SilverFoxMedia

    SilverFoxMedia

    Joined:
    Nov 7, 2009
    Posts:
    153
    -

    Yeah, I'd already used tonyd's code and changed the names of the variables and such. But thanks anyway, I really do appreciate it :D