|
- var myAudio;
- myAudio = GetComponent(AudioSource); //获取声音元件
- private var scrollVol : float = 0.5; //定义音量控制变量
- function AudioSwitch (){
- if(!myAudio.playOnAwake) //判断是否开关
- {
- myAudio.Play();
- myAudio.playOnAwake=true;
- }
- else
- {
- myAudio.Stop();
- myAudio.playOnAwake=false;
- }
- }
- function OnGUI()
- {
- scrollVol = GUI.HorizontalSlider (Rect (150,175,100,20), scrollVol, 0.0, 1.0);
- myAudio.volume = scrollVol;
- if (GUI.Button (Rect (10,10,80,30), "on")) {
- myAudio.Play();
- }
- if (GUI.Button (Rect (100,10,80,30), "off")) {
- myAudio.Stop();
- }
- }
复制代码 |
|