Question by
FunnyGuy · Nov 02, 2015 at 01:53 AM ·
c#uiaudiosourceaudioclipeditor extension
How to make an editor extension to unity ui for switching audio clips?
I've been working on a little music player that plays only what is in the program. I have a script already to hold the music, just can't figure out how to switch audio clips. I want to make a script that plays the next sound, and the next, and so on, using onClick. Any ideas? Any links? Code I was using:
using UnityEngine;
using System.Collections;
public class Audio : MonoBehaviour {
public AudioSource A_Source;
//The audioclips which you should assign through inspector
public AudioClip Clip_00;
public AudioClip Clip_01;
public AudioClip Clip_02;
public AudioClip Clip_03;
public AudioClip Clip_04;
//Singleton accessor
public static Audio Instance;
void Awake()
{Instance=this;}
void Start()
{
//Add the audio source
A_Source= gameObject.AddComponent<AudioSource>();
}
public void PlaySoundTrack(int TrackID)
{
//Stop any playing music
A_Source.Stop ();
switch (TrackID) {
case 1:
A_Source.PlayOneShot (Clip_01);
break;
case 2:
A_Source.PlayOneShot (Clip_02);
break;
case 3:
A_Source.PlayOneShot (Clip_03);
break;
case 4:
A_Source.PlayOneShot (Clip_04);
break;
default:
A_Source.PlayOneShot (Clip_00);
break;
}
}
}
Comment