码迷,mamicode.com
首页 > 其他好文 > 详细

Unity3d 背景、音效 播放 简单demo

时间:2014-06-18 22:22:47      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   tar   color   

 

仅实现功能,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

Unity3d 背景、音效 播放 简单demo

标签:style   class   blog   code   tar   color   

原文地址:http://www.cnblogs.com/hewei2012/p/3790187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!