首页 > 代码库 > Unity3d 背景、音效 播放 简单demo
Unity3d 背景、音效 播放 简单demo
仅实现功能,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); }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。