Create a health bar

时间秒杀一切 提交于 2019-12-02 13:17:40

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!