Can you tell me how to change audio track via script in Unity?
Example:
int x = 5;
if (x == 5)
{
//CHANGE AUDIO TRACK
}
CodePudding user response:
Set a reference to your audio source as well as the audio clip you're trying to play. After that it should be as simple as:
audioSource.clip = audioClip;
audioSource.Play();
CodePudding user response:
Low-level functionality is in most cases implemented via callbacks in native code. Scripts intentionally do not have access to all of Unity's APIs, nor to most of them in their entirety.
Non-Script code, i.e. usally C# code implements the required functionality and provides an easy JS or LUA API that is provided to scripts in the form of functions or objects.