I am trying to create a working health bar, and I have tried methods like
Creating GUI.Box() that contains the health bar texture that I have created, but this
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