예제 #1
0
    void ActualPlay()
    {
        if (!GhostTools.SafeToInstantiate(gameObject))
        {
            Debug.LogWarning("Audio playing is only supporting while game is running.");
            return;
        }

        if (audioCollection == null)
        {
            Debug.LogWarning(name + " has no audio connection referenced!");
            return;
        }

        GameObject audioGO = new GameObject(audioCollection.name);

        audioGO.transform.parent   = AudioParent().transform;
        audioGO.transform.position = transform.position;
        AudioSource newSource = audioGO.AddComponent <AudioSource>();

        newSource.spread                = 180;
        newSource.dopplerLevel          = 0;
        newSource.rolloffMode           = AudioRolloffMode.Linear;
        newSource.clip                  = audioCollection.GetRandomClip();
        newSource.playOnAwake           = false;
        newSource.outputAudioMixerGroup = audioCollection.mixerGroup;
        newSource.volume                = audioCollection.volume * volume;
        newSource.pitch                 = audioCollection.Pitch();
        newSource.spatialBlend          = 1;
        newSource.maxDistance           = audioCollection.maxDistance;

        newSource.Play();

        Destroy(audioGO, audioCollection.audioLifetime);
    }
예제 #2
0
    public void Play()
    {
        if (audioCollection == null)
        {
            Debug.LogWarning(name + " has no audio connection referenced!");
            return;
        }

        GameObject audioGO = new GameObject(audioCollection.name);

        audioGO.transform.parent = AudioParent().transform;
        AudioSource newSource = audioGO.AddComponent <AudioSource>();

        newSource.clip                  = audioCollection.GetRandomClip();
        newSource.playOnAwake           = false;
        newSource.outputAudioMixerGroup = audioCollection.mixerGroup;
        newSource.volume                = audioCollection.volume;
        newSource.pitch                 = audioCollection.Pitch();

        newSource.Play();
        Destroy(audioGO, audioCollection.audioLifetime);
    }