U3d a gameobject binds two audiosource, allowing them to play separately and to control
usingUnityengine;usingSystem.Collections; Public classPlaymusic:monobehaviour {Privateaudiosource[] M_arraymusic; PrivateAudiosource M_music1; PrivateAudiosource M_music2; //Use this for initialization voidStart () {M_arraymusic= gameobject.getcomponents<audiosource>(); M_music1= m_arraymusic[0]; M_music2= m_arraymusic[1]; } //Update is called once per frame voidUpdate () {if(Input.getkeydown (keycode.a)) {M_music1. Play (); } if(Input.getkeydown (KEYCODE.S)) {M_music1. Stop (); } if(Input.getkeydown (KEYCODE.E)) {M_music2. Play (); } if(Input.getkeydown (KEYCODE.R)) {M_music2. Stop (); } if(Input.getkey (KEYCODE.Q)) {M_music1.volume-=0.05f; } if(Input.getkey (KEYCODE.W)) {M_music1.volume+=0.05f; } if(Input.getkey (keycode.t)) {M_music2.volume-=0.05f; } if(Input.getkey (keycode.y)) {M_music2.volume+=0.05f; } }}
U3d a gameobject bound two Audiosource