[Unity]特效聲音播放程式碼

Unity 特效聲音播放程式碼

using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class SoundEffect : MonoBehaviour {

	public AudioClip voiceCoin;
	AudioSource audio;

	// Use this for initialization
	void Start() {
		audio = GetComponent();
		audio.volume = 1.0f;
	}

	public void PlayVoiceCoin() {
		audio.PlayOneShot(voiceCoin);
	}
}