AudioSource.PlayClipAtPoint loop ?

using UnityEngine;
using System.Collections;

public class login2 : MonoBehaviour
{
	public GUIStyle ImageBackground;
	public GUIStyle ImageButtonRegistration;
	public GUIStyle ImageButtonLogin;
	public AudioClip SoundBackground;
	public AudioClip SoundButtonClick;
	public AudioClip SoundButtonOver;
	public string lastTooltip = "";
	
	void Start ()
	{
		AudioSource.PlayClipAtPoint(SoundBackground, transform.position);
	}
	
	void OnGUI ()
	{
		GUI.Box(new Rect((Screen.width - 246 ) / 2, (Screen.height - 128 ) / 2, 246, 128), "", ImageBackground);
		if(GUI.Button(new Rect((Screen.width - 180 ) / 2, (Screen.height - -150 ) / 2, 81, 28), new GUIContent("", "SoundButtonOver"), ImageButtonRegistration))
		{
			AudioSource.PlayClipAtPoint(SoundButtonClick, transform.position);
		}
		if (GUI.Button (new Rect ((Screen.width - -15) / 2, (Screen.height - -150) / 2, 81, 28), new GUIContent("", "SoundButtonOver"), ImageButtonLogin))
		{
			AudioSource.PlayClipAtPoint(SoundButtonClick, transform.position);
		}
		if (Event.current.type == EventType.Repaint && GUI.tooltip != lastTooltip) {
			if (GUI.tooltip != "")
				AudioSource.PlayClipAtPoint(SoundButtonOver, transform.position);
			lastTooltip = GUI.tooltip;
		}
	}
}

how add to loop function "AudioSource.PlayClipAtPoint(SoundBackground, transform.position); " ?

Hello,

That is not very safe but it should work:

void Start ()
    {
        AudioSource.PlayClipAtPoint(SoundBackground, transform.position);
        GameObject source = GameObject.Find ("One shot audio");
        source.audio.loop = true;
    }

I don’t know if there is a better way to get the AudioSource generated with PlayClipAtPoint(), if only this function could return the source it would be simpler and safer.

cheers

You could look at AudioSource.loop

The usage is pretty simple, if the game object already has an audio source component attached to it. You just call it like so, I suggest calling it in the “Start” function.

audio.loop = true;

Should be as simple as that.