游戏开发常见操作梳理系列之——玩家信息的显示系统

在游戏中,有不少游戏在左上角会出现玩家的头像和等级以及血量,这就是玩家的信息显示系统,那么这些是如何制作的呢?接下来我将讲讲代码的操作,其它操作我会在其它笔记中一一说明,敬请期待!

信息的显示相当简单就是控制一些UI,然后在其它系统里面填写相应的方法即可,以下使用NGUI,你可以自己替换。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeadStatusUI : MonoBehaviour
{
    public static HeadStatusUI _instance;
    public UILabel namePlayer;

    public UISlider hpBar;
    public UISlider mpBar;

    public UILabel hpLabel;
    public UILabel mpLabel;

    private PlayerStatus ps;

    private void Awake()
    {
        _instance= this;
    }
    private void Start()
    {
        ps = GameObject.FindGameObjectWithTag(Tags.player).GetComponent<PlayerStatus>();
        UpdateShow();
    }
    // Start is called before the first frame update
    public void UpdateShow()
    {
        namePlayer.text = "Lv." + ps.level + "  " + ps.namePlayer;
        hpBar.value = ps.hp_remain / ps.hp;
        mpBar.value= ps.mp_remain / ps.mp;

        hpLabel.text = ps.hp_remain + "/" + ps.hp;
        mpLabel.text=ps.mp_remain+"/"+ ps.mp;
    }
}

希望对你有所帮助,点个赞支持一下吧!

  • 12
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nicole Potter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值