- Home /
Running a script without being attached to an object?
I've attached my script to a blank Audio Source just so that its Start() would run. However, my script's goal is to simply call functions from other scripts.
I have audio1.cs, audio2.cs and audio3.cs with each being attached to AudioSource1, AudioSource2 and AudioSource3. I then use audioControl.cs to call the functions from those 3 to play their audio.
Therefore, audioControl doesn't need an object to attach to.
How would I make this work?
Answer by IgorAherne · Oct 18, 2016 at 06:50 AM
Via a static class or
via [RunTimeInitializeOnLoadMethod] https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html
Answer by Cynikal · Oct 18, 2016 at 06:52 AM
Every single script that has a function (unless it's a static) needs to be on a game object...
If you public static class audioControl, then you don't necessarily need to add it to a gameobject, however having static functions tends to lead to its own headaches.