回顾:战利品表
本课属于 Coddy Unity 学习旅程的“Unity 游戏架构”单元。第 21 课,共 64 课。
挑战
简单填写宝箱的战利品表,使其与场景相匹配。
- 声明
public enum Rarity { Common, Rare, Epic, Legendary },并创建一个[System.Serializable]类LootEntry,其中包含公共属性string itemName、GameObject prefab、Rarity rarity。 - 为宝箱添加
public List<LootEntry> table;。 - 编写
public int WeightOf(Rarity rarity):Common 为 10,Rare 为 4,Epic 为 2,Legendary 为 1。public int TotalWeight()将它们在table中相加。
点击 “开始”:暂时不会掉落任何物品。然后点击 “检查”。
亲手试试
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class LootChest : MonoBehaviour
{
}
Unity 游戏架构中的所有课
自己练习: Unity 在线编辑器