Unity2D教程:人物状态条(头像、生命值、魔力值)

关注专栏,持续更新哦

教程总目录


  • 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;
}

猜你喜欢

转载自blog.csdn.net/jk_chen_acmer/article/details/106961110
今日推荐