Search Unity

hide Slider until needed and hide when boss is dead

Discussion in '2D' started by StrikeZero, May 23, 2019.

  1. StrikeZero

    StrikeZero

    Joined:
    Oct 20, 2017
    Posts:
    2
    hi! i'm fairly new to unity and was wondering how i could hide a the boss health slider until i need him and destroy it when hes gone.
     
  2. zioth

    zioth

    Joined:
    Jan 9, 2019
    Posts:
    111
    Is the health bar in a Canvas, or attached to the boss? If it's attached to the boss, just make it a child element of the boss, and it will go away automatically when he does.

    If it's in a Canvas, it's still easy.
    - Create the health bar with the "active" box unchecked (it's in the upper-left corner of the inspector).
    - In your code, when you want the health bar to appear, call SetActive(true) on its GameObject.
    - When the boss dies (which I assume happens in code), call SetActive(false) on the health bar.
     
  3. StrikeZero

    StrikeZero

    Joined:
    Oct 20, 2017
    Posts:
    2
    it worked, thank you very much