How to check string against multiple subclasses
I have multiple child classes (music, effects, narration, etc.) under the parent class AUDIO. I'm struggling to figure out how I can pass a string amongst all all subclasses to determine if the given file can be called (stored in its respective child class).
For example, if I am trying to call a file named "musicA1", I want to check music, effects, and narration subclasses simultaneously for that string, so I can use a single "play" function. Could I use a foreach loop on the parent class AUDIO to iterate through each subclass? I'm struggling to format that properly if so.
Thank you!
EDIT: Upon further research, there may further complications because my child classes are serialized (though the parent is not). They are declared in on script like so:
public class AUDIO
{
public string name;
public AudioClip clip;
[Range(0f, 1f)]
public float volume;
[Range(.1f, 3f)]
public float pitch;
public bool loop;
[HideInInspector]
public AudioSource source;
}
//Child classes of AUDIO
[System.Serializable]
public class Sound : AUDIO
{
}
[System.Serializable]
public class Music : AUDIO
{
}
[System.Serializable]
public class Foley : AUDIO
{
}
[System.Serializable]
public class Narration : AUDIO
{
}
In another script they are referenced, but I'm still struggling to see if I can check a string against all child classes simultaneously, rather than in a bloated series of methods.
Your answer
Follow this Question
Related Questions
Executing variables as code? 1 Answer
,Code in loop simultaneously executing on members of array rather than iterating one at a time 1 Answer
For Loop restarting early. Iteration variable restarting while loop condition is still true. 1 Answer
Iterating through children causes InvalidCastException 1 Answer
set value to 0 every forth iteration. 2 Answers