using System.Collections; using System.Collections.Generic; using UnityEngine; public enum MonsterId { Bat, Golem, } public class MonsterDatabase { private static Dictionary SPRITE_NAMES = new Dictionary { {MonsterId.Bat, "BatSprite"}, {MonsterId.Golem, "GolemSprite"}, }; public static BattleMonster createMonsterScript(MonsterId id) { switch (id) { case MonsterId.Bat: return new BatMonster(); case MonsterId.Golem: return new GolemMonster(); default: throw new System.ArgumentException("MonsterId unknown", "id"); } } public static GameObject createMonsterSprite(MonsterId id) { GameObject spritePrefab = (GameObject) Resources.Load("MonsterImages/" + SPRITE_NAMES[id]); if (spritePrefab == null) { throw new System.ArgumentException("No sprite for MonsterId", "id"); } return GameObject.Instantiate(spritePrefab); } }