在游戏中,有不少游戏在左上角会出现玩家的头像和等级以及血量,这就是玩家的信息显示系统,那么这些是如何制作的呢?接下来我将讲讲代码的操作,其它操作我会在其它笔记中一一说明,敬请期待!
信息的显示相当简单就是控制一些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;
}
}
希望对你有所帮助,点个赞支持一下吧!