-
UI里面创建4个Image,代表背景框、血条、蓝条、头像。
-
改变source image,并按下set native size恢复到原始大小
-
由于固定于左上角,所以设置锚点为左上角
-
人物状态栏最好设置大小随屏幕大小而改变
-
设置血条蓝条变动,这样设置后fill amount减少后会从右边开始减少,并且左边的部分不会变动。
-
Player下面通过脚本修改amount为health/maxHealth,蓝条同理(通过tag来找到血条)
GameObject healthBar = null;
private void SetHealthBar()
{
if (healthBar == null)
{
healthBar = GameObject.FindGameObjectWithTag("HealthBar");
}
healthBar.GetComponent<Image>().fillAmount = health / maxHealth;
}