123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using UnityEngine;
- using System.Collections;
- public class EffectSound : MonoBehaviour {
- public GameObject effectSoundShotPrefab;
- //Battle
- public AudioClip explode;
- private float volume = 1;
- //Use this for initialization
- void Awake ()
- {
- GameObject.DontDestroyOnLoad(this.gameObject);
- }
-
- public void Play(AudioClip clip, float volume=1f, float duration=float.MaxValue)
- {
- if(clip == null || this.volume == 0)
- return;
- GameObject soundObj = Instantiate(effectSoundShotPrefab) as GameObject;
- AudioSource audioSource = soundObj.GetComponent<AudioSource>();
- audioSource.volume = volume;
- audioSource.clip = clip;
- audioSource.Play();
- soundObj.GetComponent<EffectSoundShoot>().duration = duration;
- }
- public void Play(string path, float volume=1f, float duration=float.MaxValue)
- {
- AudioClip clip = Resources.Load<AudioClip>("AudioClip/"+path);
- Play (clip, volume, duration);
- }
- public void SetVolume(float volume)
- {
- this.volume = volume;
- }
- public float GetVolume()
- {
- return this.volume;
- }
- }
|