标签:style blog color io os ar for div art
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; } } }
u3d一个GameObject绑定两个AudioSource
标签:style blog color io os ar for div art
原文地址:http://www.cnblogs.com/dragon2012/p/3975765.html