我们上一节已经搭建好了游戏的场景,我们这一节进行规划游戏中的数据。
- 添加标签并取名为Enemy
添加一个新的layer取名为Ignore Bullet
打开并取消勾选Edit–Project Setting–Physics
- 新建一些文件夹
在Codes文件夹下新建脚本
并在HUD脚本中写如下程序
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HUD : MonoBehaviour
{
private static HUD instance;
public static HUD GetInstance()
{
return instance;
}
private void Awake()
{
instance = this;
}
public Image weaponIcon;
public Text bulletNum;
public Text hpNum;
public void UpdateWeaponUI(Sprite icon, int bullet_num)
{
weaponIcon.sprite = icon;
bulletNum.text = bullet_num.ToString();
}
public void UpdateHpUI(int hp_num)
{
hpNum.text = hp_num.ToString();
}
}
然后选中Canvas并且在属性中添加HUD
并将相关组件添加到属性中