创建AudioManager类,将这个脚本赋给GameManager,添加并指定AudioSource组件
using System.Collections; using System.Collections.Generic; using UnityEngine; public class AudioManager : MonoBehaviour { private static AudioManager am; public static AudioManager getAudioManager{ get{ return am; } } void Awake () { am = this; } public AudioSource audioSource; public void RandomPlayAudioInClips(AudioClip[] clips){ int index=Random.Range (0, clips.Length); //audioSource.clip = clips [index]; //audioSource.Play (); audioSource.PlayOneShot (clips [index]); } public void PlayAudioClip(AudioClip clip){ //audioSource.clip = clip; //audioSource.Play (); audioSource.PlayOneShot (clip); } }
在其他地方就可以通过以下方式调用,很是方便
public AudioClip[] attackClips; AudioManager.getAudioManager.RandomPlayAudioInClips (attackClips);
public AudioClip damageClip; AudioManager.getAudioManager.PlayAudioClip (damageClip);
暂无关于此日志的评论。