Is it possible to access all variables of a given type within a C# script?
Specifically, I’d like to take a whoooole bunch of AudioClip variables and, in the Start() function, put them all into an array (without having to manually add every AudioClip). Basically, the working equivalent of:
Hmm. Well, I don’t think you can do what you added in for code, but I know one thing you can do.
using System.Collections;
using UnityEngine;
public class YourClassName
{
private AudioSource[] sources;
public void Start()
{
SetSources(new AudioSource source1, new AudioSource source2);
}
public void SetSources(AudioSource[] SourceList)
{
sources = SourceList;
}
}