unity3d学习笔记(一)-在一个GameObject上进行多个AudioSource的控制
生活随笔
收集整理的這篇文章主要介紹了
unity3d学习笔记(一)-在一个GameObject上进行多个AudioSource的控制
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
using UnityEngine;
using System.Collections;public class SoundSwitch : MonoBehaviour {public AudioSource as1;public AudioSource as2;public AudioClip[] a1;// Use this for initializationvoid Start () {//代碼關(guān)鍵點(diǎn)1(可選):增加兩個(gè)AudioSource到GameObjectthis.gameObject.AddComponent("AudioSource");this.gameObject.AddComponent("AudioSource");//代碼關(guān)鍵點(diǎn)2:GetComponents方法獲得所有該GameObj上的AudioSource對(duì)象。這樣就可以分別進(jìn)行控制了。var as_array=this.gameObject.GetComponents(typeof(AudioSource));as1=(AudioSource)as_array[0];as2=(AudioSource)as_array[1];as1.clip=a1[1];as2.clip=a1[2];AudioPlay();}// Update is called once per framevoid Update () {}void AudioPlay(){as2.Play();as1.Play();}
}
轉(zhuǎn)載于:https://www.cnblogs.com/crazycowboy/archive/2012/06/28/2567213.html
總結(jié)
以上是生活随笔為你收集整理的unity3d学习笔记(一)-在一个GameObject上进行多个AudioSource的控制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C#定义属性-静态属性
- 下一篇: 类中匿名函数如何从 event 中去除