I’m trying to have a sound play on an empty game object using a UI button with the new UI system. I basically have this script on an empty game object with a sound file as sound source.
But when I ad another button state and try and use the stop sound the button does not work at all, but I can get it to play with the first play sound option.
I’m not good at C# so I’m sure I’m buggering this up with the new UI somehow.
using UnityEngine;
using System.Collections;
public class PodScannerSoundManager : MonoBehaviour {
public void ScannerPlay()
{
audio.Play();
}
public void ScannerStop()
{
audio.Stop();
}
}
It’s normal because you are calling all your method on Click.
So it will call audio.Stop() in the end…
Call just one (and only one) function from the button:
public void TogglePlay()
{
if(audio.isPlaying)
{
audio.Stop();
}
else
{
audio.Play();
}
}
Cheers