using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(AudioPlayer))] public class AudioPlayerTest : MonoBehaviour { public string AudioFile; private AudioPlayer audioPlayer; void Start() { audioPlayer = GetComponent(); } void OnGUI() { GUILayout.BeginArea(new Rect(200, 0, 200, 600)); GUILayout.BeginVertical(); GUILayout.Label("播放器测试:"); if (GUILayout.Button("开始播放")) audioPlayer.Play(AudioFile); if (GUILayout.Button("停止播放")) audioPlayer.Stop(); GUILayout.EndVertical(); GUILayout.EndArea(); } }