Unity 爱心血量效果

这里写自定义目录标题

1.准备爱心血条

准备好红色爱心和灰色爱心的图片

2.HeartUI 代码

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Hearts : MonoBehaviour {
    [Header("爱心UI图的列表")]public List<Image> redHearts = new();

    void Start () 
    {

    }

    public void UpdateHeartUI(int HP)
    {
        //先将所有红色爱心全部隐藏
        foreach (Image redHeart in redHearts)
        {
            redHeart.enabled = false;
        }
        //再根据HP数量先将爱心依次显示
        for (int i=0; i< HP; i++)
        {
            redHearts[i].enabled = true;
        }
    }   
}

3.在Inspector窗口中绑定好对象


4.在血量减少的地方,调用更新方法

5.效果展示

相关推荐
淡海水1 小时前
【节点】[Branch节点]原理解析与实际应用
unity·游戏引擎·shadergraph·图形·branch
在路上看风景1 小时前
4.6 显存和缓存
unity
Zik----4 小时前
简单的Unity漫游场景搭建
unity·游戏引擎
在路上看风景14 小时前
4.5 顶点和片元
unity
在路上看风景1 天前
31. Unity 异步加载的底层细节
unity
天人合一peng1 天前
Unity中做表头时像work中整个调整宽窄
unity
小李也疯狂2 天前
Unity 中的立方体贴图(Cubemaps)
unity·游戏引擎·贴图·cubemap
牛掰是怎么形成的2 天前
Unity材质贴图引用陷阱:包体暴涨真相
unity·材质·贴图
呆呆敲代码的小Y2 天前
【Unity工具篇】| 超实用工具LuBan,快速上手使用
游戏·unity·游戏引擎·unity插件·luban·免费游戏·游戏配置表
EQ-雪梨蛋花汤2 天前
【Unity优化】Unity多场景加载优化与资源释放完整指南:解决Additive加载卡顿、预热、卸载与内存释放问题
unity·游戏引擎