I’m making a game where the dialogue box can pull each character sprite through an enum based on what the emotion I want is.
The current enum is this:
DialogueManager:
public enum AylaSprites
{
Base,
Confused,
Happy,
Point,
Sad
}
And in another file I want to be able to access them on the fly using a string list I can add in Unity’s timeline inspector. A list of sprites won’t allow me to select the function and I already have the enums for a different script, so I’d like to use them if possible.
I was hoping I could just go about it similar to concat-ing strings, like
TutorialTimeline:
(dManager is this scripts reference to the Dialogue Manager, and spriteOptions is a
list in that manager)
List<Sprite> spriteList = new List<Sprite>();
foreach (var sprite in newSprites)
{
spriteList.Add(dManager.spriteOptions[(int)DialogueManager.AylaSprites.**(sprite)**]);
}
but obviously that’s not possible. Is there any way I could somehow do something similar?
Is there a way for me to just stick the string onto the end there? Or do I need to take a different approach?
3
If you’re “Happy” AND “Confused”, you may want to consider a “flag” enum; which uses bits to select “zero, one or more” options using a single field / property. So, instead of working with a “list” of attributes and string operators, you can use a “flag” enum and boolean operators.
https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-flagsattribute