Problem with AudioSource.Play()

Hi Everyone,

I know this sounds weird, but I’m not sure if it’s something I’m doing wrong.

I need an object to start emitting sound after certain Event and also trigger an Animation so:

[SerializeField]
	private Animator myAnim;
	[SerializeField]
	private AudioSource sound;

	void Start()
	{
		myAnim = GetComponent<Animator>();
		sound = this.GetComponent<AudioSource> ();
	}

	public void PowerConveyorBelt()
	{    
		sound.Play ();
		myAnim.SetBool("IsON", true);
	}

This simple script is not working. If I check the Play on Awake in the AudioSource component, the sound plays nice and smooth…

Is there another method to do this? Does the Animator interfere with the AudioSource?

I kind of listen to noise and interference when they Play through the scritp. Is there a Parameter I should be touching?

Thanks everyone in advance.

I forgot. For this specific project I’m using a very old version of Unity (5.2)

  • If you write sound.Play() inside void
    start() will it play?

  • Have you attached everything
    correctly?

  • Is the event trigger beeing
    triggered at all and initiating
    “PowerconveyorBelt()”?

Ok kids… this is why you should sleep before you code xD

My problem that I was treating AudioSource.Play() as a trigger. And it’s not… What was happening is that the sound was being play once and again and again…

A simple condition AudioSource.IsPlaying == true fixed the issue… U.U