Recap: Loot Table
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 21 of 64.
Challenge
EasyFill the chest's loot table to match the scene.
- Declare
public enum Rarity { Common, Rare, Epic, Legendary }and a[System.Serializable]classLootEntrywith publicstring itemName,GameObject prefab,Rarity rarity. - Give the chest
public List<LootEntry> table;. - Write
public int WeightOf(Rarity rarity): Common 10, Rare 4, Epic 2, Legendary 1.public int TotalWeight()adds them overtable.
Press Play: nothing drops yet. Then Check.
Try it yourself
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class LootChest : MonoBehaviour
{
}
All lessons in Game Architecture in Unity
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular TurretRecap: Twin Cannon4Serialized Data
Serializable ClassesLists in the InspectorEnums in the InspectorRecap: Loot TableRecap: Roll the Loot2Interfaces in Unity
IDamageableInterfaces and TryGetComponentGetComponentsRecap: Interact KeyRecap: Nearest in ReachPractice on your own: Unity playground