/// <summary> /// Creates a one shot sound that will follow target transform /// </summary> /// <param name="clip">The audio clip</param> /// <param name="targetTransform">The transform</param> /// <param name="vol">The volume</param> public virtual void CreateOneShotFollowTarget(AudioClip clip, Transform targetTransform, float vol) { _plauAudioAndDisable = GetOneShotObject(); if (_plauAudioAndDisable == null) { Debug.LogWarning("No component source was found..."); return; } //Add it to list in order to properly pause the game _plauAudioAndDisable.gameObject.SetActive(true); _plauAudioAndDisable.PlayAndDisable(clip, vol, targetTransform); }
private PlayAudioAndDisable GetOneShotObject() { PlayAudioAndDisable audioObj = null; if (_poolingController == null) { audioObj = Instantiate(_audioPrefab).GetComponent <PlayAudioAndDisable>(); audioObj.SetDestroyWhenDone(true); } else { audioObj = _poolingController.GetPooledObject(_audioPrefab).GetComponent <PlayAudioAndDisable>(); } return(audioObj); }
/// <summary> /// Creates a one shot sound that will be stationary /// </summary> /// <param name="clip"></param> /// <param name="pos"></param> /// <param name="vol"></param> public virtual void CreateOneShot(AudioClip clip, Vector3 pos, float vol = 1f) { _plauAudioAndDisable = GetOneShotObject(); if (_plauAudioAndDisable == null) { Debug.LogWarning("No component source was found..."); return; } _plauAudioAndDisable.transform.position = pos; //Add it to list in order to properly pause the game _plauAudioAndDisable.gameObject.SetActive(true); _plauAudioAndDisable.PlayAndDisable(clip, vol); }