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)); }
// 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)); }
private static void ChangeMusic(AudioType audioType, string path, bool isListener) { string audioSourceUid = soundSourceUID; Torch.DestroyObject(audioSourceUid); soundSourceUID = null; PlayMusic(audioType, path, isListener); if (!isListener) { RemoveListener(); } }