- Home /
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); " ?
Answer by Nerevar · Jul 10, 2014 at 09:47 AM
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
Answer by Flickayy · Jul 10, 2014 at 02:30 AM
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.
No No No ! You Code Error !
I need -> loop SoundBackground !
That's because you need an "Audio Source" component. This is where the sound comes from. Works fine for me.
It tells you clearly in the error message...
Your answer
Follow this Question
Related Questions
how do i make footsteps only sound when i move in the area i place the audio? 1 Answer
how to start audioloop synced to one playing 1 Answer
How to make my music come on for a certain amount of time every few minutes 0 Answers
Audio source data? 0 Answers
Best way to play audio sound effects 1 Answer