SpaceShooter_Project/Assets/Scripts/Audio/AudioManager.cs
/// <summary>
/// Get audio source object from object pool.
/// </summary>
Get audio source object from object pool.
Get audio source object from object pool .
protected AudioSource GetAudioSource(Vector3 position, bool forceInstantiate = false)
    {
        if (_audioSourcePrefab == null)
        {
            Debug.LogWarning("Cannot generate a audio source because AudioSourcePrefab is not set.");
            return null;
        }
        var goAudioSource = ObjectPool.Instance.GetGameObject(_audioSourcePrefab, position, Quaternion.identity, forceInstantiate);
        if (goAudioSource == null)
        {
            Debug.LogError("Failed to pool audio source prefab.");
            return null;
        }
        var audioSource = goAudioSource.GetComponent<AudioSource>();
        if (audioSource == null)
        {
            Debug.Log("Adding audio source component");
            audioSource = goAudioSource.AddComponent<AudioSource>();
        }
        return audioSource;
    }
protected AudioSource GetAudioSource ( Vector3 position , bool forceInstantiate = false ) { if ( _audioSourcePrefab == null ) { Debug . LogWarning ( " " ) ; return null ; } var goAudioSource = ObjectPool . Instance . GetGameObject ( _audioSourcePrefab , position , Quaternion . identity , forceInstantiate ) ; if ( goAudioSource == null ) { Debug . LogError ( " " ) ; return null ; } var audioSource = goAudioSource . GetComponent < AudioSource > ( ) ; if ( audioSource == null ) { Debug . Log ( " " ) ; audioSource = goAudioSource . AddComponent < AudioSource > ( ) ; } return audioSource ; }
Get audio source object from object pool.
Get audio source object from object pool .
// get Bullet GameObject from ObjectPool // get or add Bullet component
position
Vector3
forceInstantiate
bool