仅实现功能,AudioListener在MainCamera中
using UnityEngine; using System.Collections; using System.Collections.Generic; public class MusicManger : MonoBehaviour { AudioSource _backMusicSource = null; AudioSource _SoundSource = null; //public string musicName = ""; // Use this for initialization void Start () { _backMusicSource = gameObject.AddComponent<AudioSource>(); _backMusicSource.loop = true; _SoundSource = gameObject.AddComponent<AudioSource>(); PlayMusic("Music/test"); PlaySound("Music/test1"); } void PlayMusic(string musicPath) { AudioClip clip = Resources.Load(musicPath) as AudioClip; _backMusicSource.clip = clip; _backMusicSource.Play(); } void PlaySound(string soundPath) { AudioClip clip = Resources.Load(soundPath) as AudioClip; _SoundSource.PlayOneShot(clip); } }
Unity3d 背景、音效 播放 简单demo,布布扣,bubuko.com
原文:http://www.cnblogs.com/hewei2012/p/3790187.html