Пример #1
0
    public static void Play3DSoundFromList(int index, Vector3 position)
    {
        GameObject soundGameObject = new GameObject("Sound");

        soundGameObject.transform.position = position;
        AudioSource audioSource = soundGameObject.AddComponent <AudioSource>();

        audioSource.volume       = 0.9f;
        audioSource.maxDistance  = 150f;
        audioSource.spatialBlend = 1f;
        audioSource.rolloffMode  = AudioRolloffMode.Linear;
        audioSource.dopplerLevel = 0f;
        audioSource.PlayOneShot(GameAssets.instance.explosionSoundClips[index]);

        DestroyOnDelay.Destroy(soundGameObject, 2F);
    }
Пример #2
0
    public static void Play3DSound(Sound sound, Vector3 position)
    {
        if (CanPlaySound(sound))
        {
            GameObject soundGameObject = new GameObject("Sound");
            soundGameObject.transform.position = position;
            AudioSource audioSource = soundGameObject.AddComponent <AudioSource>();
            audioSource.clip         = GetAudioClip(sound, false);
            audioSource.volume       = 0.9f;
            audioSource.maxDistance  = 150f;
            audioSource.spatialBlend = 1f;
            audioSource.rolloffMode  = AudioRolloffMode.Linear;
            audioSource.dopplerLevel = 0f;
            audioSource.Play();

            DestroyOnDelay.Destroy(soundGameObject, 2F);
        }
    }