Unity点击按钮重放,用按钮控制动画的播放,暂停,重播,求高手解答,在线等
2个回答
展开全部
using UnityEngine;using System.Collections;
public class MusicControlScript : MonoBehaviour {
public AudioSource music;
public float musicVolume;
public Rect windowRect = new Rect(700, 20, 90, 225);
bool showGUI;
void Start() {
showGUI=false;
musicVolume = 1.0F;
}
void OnGUI() {
if(GUI.Button(new Rect(Screen.width-60,5,50,50),"Music"))
{
showGUI=true;
}
if(showGUI)
windowRect = GUI.Window(0, windowRect, DoMyWindow, "Music");
}
void DoMyWindow(int windowID){
if(GUI.Button(new Rect(75,5,10,10),""))
{
showGUI=false;
}
if (GUI.Button(new Rect(5, 30, 45, 45), "Play")) {
if (!music.isPlaying){
music.Play();//播放
}
}
if (GUI.Button(new Rect(5, 85, 45, 45), "Stop")) {
if (music.isPlaying){
music.Stop();//停止
}
}
if (GUI.Button(new Rect(5, 140, 45, 45), "Pause")) {
if (music.isPlaying){
music.Pause();//暂停
}
}
musicVolume = GUI.VerticalSlider (new Rect(65, 30, 30, 150), musicVolume, 0.0F, 1.0F);//声音调节
GUI.Label(new Rect(5, 190, 90, 20), "Voice: " + (int)(musicVolume * 100) + "%");
if (music.isPlaying){
music.volume = musicVolume;
}
GUI.DragWindow(new Rect(0, 0, 100, 30));
}
}
public class MusicControlScript : MonoBehaviour {
public AudioSource music;
public float musicVolume;
public Rect windowRect = new Rect(700, 20, 90, 225);
bool showGUI;
void Start() {
showGUI=false;
musicVolume = 1.0F;
}
void OnGUI() {
if(GUI.Button(new Rect(Screen.width-60,5,50,50),"Music"))
{
showGUI=true;
}
if(showGUI)
windowRect = GUI.Window(0, windowRect, DoMyWindow, "Music");
}
void DoMyWindow(int windowID){
if(GUI.Button(new Rect(75,5,10,10),""))
{
showGUI=false;
}
if (GUI.Button(new Rect(5, 30, 45, 45), "Play")) {
if (!music.isPlaying){
music.Play();//播放
}
}
if (GUI.Button(new Rect(5, 85, 45, 45), "Stop")) {
if (music.isPlaying){
music.Stop();//停止
}
}
if (GUI.Button(new Rect(5, 140, 45, 45), "Pause")) {
if (music.isPlaying){
music.Pause();//暂停
}
}
musicVolume = GUI.VerticalSlider (new Rect(65, 30, 30, 150), musicVolume, 0.0F, 1.0F);//声音调节
GUI.Label(new Rect(5, 190, 90, 20), "Voice: " + (int)(musicVolume * 100) + "%");
if (music.isPlaying){
music.volume = musicVolume;
}
GUI.DragWindow(new Rect(0, 0, 100, 30));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |