Create a health bar

前端 未结 1 1279
醉话见心
醉话见心 2021-01-29 07:18

I am trying to create a working health bar, and I have tried methods like

  1. Creating GUI.Box() that contains the health bar texture that I have created, but this

相关标签:
1条回答
  • 2021-01-29 07:56

    Remove all API that starts with GUI.... then remove your On GUI(){....} function.

    SLIDER:

    Go to GameObject->UI->Slider.

    Delete Handle Slide Area from the slider.

    Then to control the health bar from script:

    First, Include using UnityEngine.UI;

    public Slider healthBar;
    
    //Initialize health bar
    void Start()
    {
    healthBar.interactable = false;
    healthBar.minValue = 0;
    healthBar.maxValue = 100;
    healthBar.value = 100;
    }
    

    You can then change your health bar with healthBar.value.

    FOR THE BAG IMAGE:

    Go to GameObject-UI->Image. Stop using the old GUI.

    https://unity3d.com/learn/tutorials/topics/user-interface-ui

    0 讨论(0)
提交回复
热议问题