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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Restart of values of UI Image.FillAmount and UI Text.text method after player respawn

Discussion in 'Scripting' started by HolyNova, May 21, 2015.

  1. HolyNova

    HolyNova

    Joined:
    May 19, 2015
    Posts:
    13
    Hello,

    I would like to ask for a help with my problem. I have a player game object. This game object is respawned after he is killed, using prefab. I am also using a healtbar for him and a text inside that healthbar. This is achieved by Image (filled) and Text UI elements. When player is respawned, I want to set fillamout back to 1 (so the healthbar is full) and text to the full HP which player has after respawn. I can't figure it out.

    I tried to use a simple
    Code (CSharp):
    1. visualHealth.fillAmount = 1f;
    or
    Code (CSharp):
    1. visualHealth.fillAmount = Mathf.Lerp(1, 1, 0f);
    which both should set fillAmount to 1, but it does not do anything. Could anyone help me please?

    Here is the player class: http://pastebin.com/uRqUVL4X
    here is method responsible for respawn: http://pastebin.com/ePidNbmH

    Thank you very much :)
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    healthText and visualHealth are linked via the inspector?
     
  3. HolyNova

    HolyNova

    Joined:
    May 19, 2015
    Posts:
    13
  4. HolyNova

    HolyNova

    Joined:
    May 19, 2015
    Posts:
    13
    bump. Does anyone please have an idea? I can't figure it out :/ Thanks to everyone