Forum begins after the advertisement:

 


[Part 14] Max health bug / issue

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 14] Max health bug / issue

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18984
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    In the Part 14 article, the PlayerController script had stealth changes made to it that caused the player’s health to be able to exceed the maximum limit, and which made it impossible to get extra health.

    To rectify this, you’ll need to make the following changes to your PlayerController script (we’re basically reverting this section to what it was in Part 13):

    public int Health
    {
        get { return health; }
        set
        {
            if (health != value)
            {
                health = Mathf.Max(value, 0);
                health = Mathf.Clamp(value, 0, maxHealth);
                UIManager.UpdateHealthUI(health, maxHealth, excessHealth);
            }
        }
    }
    public int ExcessHealth
    {
        get { return excessHealth; }
        set
        {
            if (excessHealth != value)
            {
                excessHealth = Mathf.Clamp(value, 0, excessHealth);
                excessHealth = Mathf.Max(value, 0);
                UIManager.UpdateHealthUI(health, maxHealth, excessHealth);
            }
        }
    }
    #18986
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Basically, the changes made are that we should be clamping the health value to the value of max health, while not clamping the value of excess health, because you can have as many blue hearts as you want.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: