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.效果展示

相关推荐
小白学鸿蒙11 小时前
Unity 3D 2023解压安装,配置安卓运行环境后打包安卓应用(踩坑无数之差点放弃)
android·unity·游戏引擎
__water20 小时前
【关于unity打包Android失败问题】
android·unity
mascon1 天前
Unity 编辑器扩展
unity·编辑器·游戏引擎
程序员正茂1 天前
Unity3d使用MQTT异步连接服务端
mqtt·unity·异步
mxwin1 天前
在unity shader中,通过pass产生阴影,通过主pass的光照 接收阴影!那么问题来了,是先产生阴影吗?还是先接收阴影,执行顺序是啥呢
数码相机·unity·游戏引擎·shader
小贺儿开发1 天前
《唐朝诡事录之长安》——盛世马球
人工智能·unity·ai·shader·绘画·影视·互动
蒙双眼看世界2 天前
Unity结合ECharts图表及网页插件EmbeddedBrowser的应用开发
unity·游戏引擎·echarts
郝学胜-神的一滴2 天前
中级OpenGL教程 004:为几何体注入法线灵魂
c++·unity·游戏引擎·godot·图形渲染·opengl·unreal
la_vie_est_belle3 天前
Pygame Studio——用Python自制的一款可视化游戏编辑器
python·游戏·编辑器·游戏引擎·pygame·pyside6·pygame-ce
LF男男4 天前
GameManager.cs
unity