u3d一个GameObject绑定两个AudioSource

u3d 一个GameObject绑定两个AudioSource  ,使他们分别播放,并控制
using UnityEngine;
using System.Collections;

public class PlayMusic : MonoBehaviour 
{
    private AudioSource[] m_ArrayMusic;
    private AudioSource m_music1;
    private AudioSource m_music2;

    // Use this for initialization
    void Start ()
    {
        m_ArrayMusic = gameObject.GetComponents<AudioSource>();
        m_music1 = m_ArrayMusic[0];
        m_music2 = m_ArrayMusic[1];
        
    }
    
    // Update is called once per frame
    void Update () 
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            m_music1.Play();
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            m_music1.Stop();
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            m_music2.Play();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            m_music2.Stop();
        }

        if (Input.GetKey(KeyCode.Q))
        {
            m_music1.volume -= 0.05f;
        
        }
        if (Input.GetKey(KeyCode.W))
        {
            m_music1.volume += 0.05f;
        }
        if (Input.GetKey(KeyCode.T))
        {
            m_music2.volume -= 0.05f;

        }
        if (Input.GetKey(KeyCode.Y))
        {
            m_music2.volume += 0.05f;
        }


    }
}

 

posted on 2014-09-16 20:44  c_dragon  阅读(2623)  评论(0编辑  收藏  举报

导航