public static void CreateSoundEffect(string url, Vector3 playPos) { string uid = Torch.CreateObject(null); Torch.SetPrefab(uid, "Prefabs/SoundEffect"); GameObject audioPlayer = Torch.GetTransform(uid).gameObject; Torch.SetTransformPosition(uid, playPos); AudioClip clip = (AudioClip)Resources.Load(url, typeof(AudioClip)); if (clip == null) { return; } AudioSource source = (AudioSource)audioPlayer.GetComponent("AudioSource"); if (source == null) { source = (AudioSource)audioPlayer.AddComponent <AudioSource>(); } source.clip = clip; source.loop = false; source.volume = 1.0f; source.Play(); source.DOFade(0f, 1f).OnComplete(() => Torch.DestroyObject(uid)); }
private static void RemoveListener() { string audioSourceUid = soundSourceUID; Transform audTrans = Torch.GetTransform(audioSourceUid); audTrans.GetComponent <AudioListener>().enabled = false; }
private static AudioSource GetAudioSource() { string audioSourceUid = soundSourceUID; Transform audioTrans = Torch.GetTransform(audioSourceUid); AudioSource audioSource = audioTrans.GetComponent <AudioSource>() as AudioSource; return(audioSource); }
// Update is called once per frame public static void Update(string uid) { if (Input.GetKey("d")) { Torch.DestroyObject(uid); } Transform thisTransform = Torch.GetTransform(uid); thisTransform.Rotate(new Vector3(Random.value * 10, Random.value * 10, Random.value * 10)); }
public static AudioSource LoadSound(string uid, string url, bool loop) { AudioClip clip = (AudioClip)Resources.Load(url, typeof(AudioClip)); GameObject audioPlayer = Torch.GetTransform(uid).gameObject; if (clip == null) { return(null); } AudioSource source = (AudioSource)audioPlayer.GetComponent("AudioSource"); if (source == null) { source = (AudioSource)audioPlayer.AddComponent <AudioSource>(); } source.clip = clip; source.loop = loop; return(source); }