Combining gameObject and enum

Hello, I created a script that contains enum. The problem is that I want it to be associated with objects, for example: there is a value in enum called TNT and I also have a prefab called that so how can I get the prefab by the enum? Is it too much to do it manually there are hundreds of values there is an automatic way?

Dictionaries might serve you better. I’m assuming you are spawning said prefabs you are trying to associate with enums.

//your variables
Dictionary<string, GameObject> gameObjectDic;

//populating dictionary
gameObjectDic.Add("TNT", /*your prefab here*/);

//example spawn using string tag
GameObject spawnedGO = Instantiate(gameObjectDic["TNT"]);

You can concievably make a dicitonary like so to use your existing enums as the key instead of a string

enum myEnum{ TNT, ... }

Dictionary<myEnum, GameObject> gameObjectDic;

Dictionaries have no in-editor representation in the inspector, so you either have to populate this purely in script, or create your own in-editor representation with editor scripting, assuming you need it to appear in inspector.

t

tanks!