Audio Clip constantly play

Hey guys, Ive got Pickups around the scene which have a sound script attached to them. when I play the game, all the sounds are playing straight away, how do I stop that from happening and only playing the sound when player picks it up.

using UnityEngine;
using System.Collections;

public class PlaySound : MonoBehaviour 
{
	public AudioClip pickupSound;

	void OnTriggerEnter(Collider Other)
	{
		AudioSource.PlayClipAtPoint(pickupSound, gameObject.transform.position);
		//audio.Play();
	}
}

1 Answer

1

You’ll need to change two settings on each AudioSource:

  • Loop: if true, the audio will loop; if false, it will play once and stop
  • Play On Awake: if true, the audio will play automatically as soon as it exists; if false, it will wait until something tells it to play

Depending on your workflow, it may be easier to change these fields in the Inspector or in a script. You can do either just fine; it’s just a question of which is simpler for you.