Why Doesn't My Music Loop?

I have an audio clip that plays when my game starts up, but it doesn’t loop. I’m not sure why it doesn’t loop.

Here’s the code exactly as it stands, it’s not too complicated.

#pragma strict

function Start () {
	AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
}

function Update () {
	
	// Play the audio for this image
	if (audio.isPlaying != true)
		AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
		
	Debug.Log(audio.loop);
}

The Debug.Log line is reporting true. My music ends, and the sound does not get played again. How do I get my sound to loop?

Have you actually physically checked that the audio sources loop is set to true(box with check mark). If not, un click “Maximize On Play” and look at the offending audio source while the game is playing.

You can’t loop sounds started with AudioSource.PlayClipAtPoint. This method doesn’t use the AudioSource component of your object but instead creates a temporary (and hidden) object. This is the intended behaviour.

As mentioned in documentation, you can use an alternative method. See http://unity3d.com/support/documentation/ScriptReference/AudioSource.PlayClipAtPoint.html for more details.

Strange, the “alternative method” from that link has disappeared. Maybe Unity removed that function in the latest build? Anyway, it’s missing from the doc link above now.

When I used the code it would also try to crash my computer with it spamming 379 messages saying “True” per 30 seconds, any fixes? It lagged so badly it dropped me down to 0 Frames Per Second, I spent 10 minuets to restore my computer’s memory usage to normal.
EDIT: Now it’s spamming the music!
EDIT:IT WORKS!!!:

 #pragma strict
 
 function Start () {
     AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
     transform.GetComponent(AudioSource).audio.loop=true;
 }
 
 function Update () {
     
     // Play the audio for this image
     if (audio.isPlaying != true)
         AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
         
 }

Thanks, that helped a lot.

The problem might be a result of using “Play on awake”.
I attached a script to the Audio Source instead and it solved the problem.

using UnityEngine;
using System.Collections;

public class MusicPlayer : MonoBehaviour 
{
	public AudioClip clip;  // Drag the clip here on the editor
	private AudioSource au;

	void Start() 
	{
		au = GetComponent<AudioSource>();
		au.loop = true;
		au.Play();
	}
}