Unity播放声音代码
using UnityEngine;using System.Collections;
public class Sound : MonoBehaviour
{
public AudioClip[] sound;
void Start () {
}
void Update () {
}
public void SoundPlay(int number)
{
audio.clip = sound;
audio.Play();
}
public void SoundPlay(AudioClip clip)
{
audio.clip = clip;
audio.Play();
}
}
-------------------------------------------------------
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
//宣告music陣列放置音樂檔
public AudioClip[] music;
//宣告musicObject
public GameObject musicObject;
public GameObject ani;
void Start()
{
}
//吁叫Sound裡SoundPlay()
void Update()
{
for(int i=0;i<3;i++)
{
musicObject.GetComponent<Sound>().SoundPlay(music);
}
} 很不错 楼主是超人 顶顶多好 真心顶 难得一见的好帖 楼主是超人 好帖就是要顶 顶顶多好 真心顶