Stop audio from looping and play at lower volume

When my player dies I stop the game music that’s attached to a game object with an audio source. I then play the “game over” music which is activated through the audio source on my player. I’m just starting out w/ audio in unity so I’m hoping this is just an easy fix. Currently none of my audio commands (audio.volume, audio.loop, audio.panLevel) work… and i’m not sure why. I just want the “game over” music to play one time at a lower volume level. currently it’s playing at max volume and keeps looping. Any help to fix this is appreciated. Thanks!

     if (currentLife == 0){
        GetComponent(EnemyDestroyPlayer).enabled = false;
        Time.timeScale = 0.0001;
        gameMusic.active = false;
        if(!audio.isPlaying) {
audio.clip = playerDeath;
audio.Play();
audio.loop = false;
audio.volume = 0.1;
audio.panLevel = 0.0;
}
        player.animation["Die"].wrapMode = WrapMode.ClampForever;
        player.animation.Play("Die");
        player.animation["Die"].speed = 1.0/Time.timeScale;
        yield WaitForSeconds(5.0 * Time.timeScale);
        	Camera.main.GetComponent(GameManager).SetGameOver(); 
        
        }

audio gives you the AudioSource attached to the current GameObject (script reference).

AudioSource.PlayClipAtPoint() is a static function, and I think creates a brand new AudioSource for the playback. Handy in a pinch if you just want to play a clip, but not as much if you need to control it past that. The script reference page for that function includes a bit of example code which can give you that control.

So you are adjusting the volume of an AudioSource – probably not the right one, though. :wink:

As far as the looping, you might be able to set that in the clip. I know you can set it on an AudioSource, in the inspector or at runtime, by toggling its loop flag.