Beispiel #1
0
    /// <summary>
    /// Creates an AudioClipPlayer and plays it in a given world space.
    /// </summary>
    /// <param name="toPlay">The audio clip to be played.</param>
    /// <param name="position">The position in world space to play the audio from.</param>
    /// <param name="minVolume">The minimum volume of the clip. (To be combined with the audio managers volume modifier)</param>
    /// <param name="maxVolume">The maximum volume of the clip. (To be combined with the audio managers volume modifier)</param>
    /// <param name="minPitch">The minimum pitch of the clip.</param>
    /// <param name="maxPitch">The maximum pitch of the clip.</param>
    /// <param name="minPan">The minimum left to right pan of the clip.</param>
    /// <param name="maxPan">The maximum left to right pan of the clip.</param>
    public void PlayClipWorldSpace(AudioClip toPlay, Vector3 position, float minVolume = 1f, float maxVolume = 1f, float minPitch = 1f, float maxPitch = 1f, float minPan = 0f, float maxPan = 0f)
    {
        if (toPlay == null)
        {
            Debug.LogError("AudioManager cannot play a null clip in the world space position " + position.ToString());
            return;
        }
        PooledObject obj = ObjectPoolingManager.instance.CreateObject(audioClipPlayer);

        obj.transform.position = position;
        AudioClipPlayer clipPlayer = obj.GetComponent <AudioClipPlayer>();

        clipPlayer.PlaySoundRandom(toPlay, minVolume, maxVolume, minPitch, maxPitch, minPan, maxPan);
    }
Beispiel #2
0
    /// <summary>
    /// Creates an AudioClipPlayer and plays it in local space.
    /// </summary>
    /// <param name="toPlay">The audio clip to be played.</param>
    /// <param name="minVolume">The minimum volume of the clip. (To be combined with the audio managers volume modifier)</param>
    /// <param name="maxVolume">The maximum volume of the clip. (To be combined with the audio managers volume modifier)</param>
    /// <param name="minPitch">The minimum pitch of the clip.</param>
    /// <param name="maxPitch">The maximum pitch of the clip.</param>
    /// <param name="minPan">The minimum left to right pan of the clip.</param>
    /// <param name="maxPan">The maximum left to right pan of the clip.</param>
    public void PlayClipLocalSpace(AudioClip toPlay, float minVolume = 1f, float maxVolume = 1f, float minPitch = 1f, float maxPitch = 1f, float minPan = 0f, float maxPan = 0f)
    {
        if (toPlay == null)
        {
            Debug.LogError("AudioManager cannot play a null clip in local space.");
            return;
        }
        PooledObject obj = ObjectPoolingManager.instance.CreateObject(audioClipPlayer, Camera.main.transform, -1);

        obj.transform.Reset();
        AudioClipPlayer clipPlayer = obj.GetComponent <AudioClipPlayer>();

        clipPlayer.PlaySoundRandom(toPlay, minVolume, maxVolume, minPitch, maxPitch, minPan, maxPan);
    }