Create Custom Variables on an Object?

Is it possible for a variable to have a custom variable, e.g., I do a foreach on a collection of AudioSources, I want to declare a variable to each AudioSource so I can manipulate it later.

Like this (doesn’t work, illustration only):

foreach (AudioSource aSrc in allAudioSources) {
bool aSrc.firstTime = true;
}

Probably the easiest way is to create your own object that contains two things: and AudioSource and your .firstTime boolean. In your Start() function you’d make an array of your own object types and stuff the AudioSources in, then always iterate that list of your type of object.

That makes sense, thanks Kurt!

1 Like