public void ChangeScript(ScriptBase pScript) { if (pScript is NpcScript npc) { NpcScript?.Dispose(); QuestScript?.Dispose(); NpcScript = npc; } else if (pScript is QuestScript quest) { QuestScript?.Dispose(); QuestScript = quest; } else { throw new ScriptException("Trying to pass a ScriptBase object that isn't handled."); } }