I have a simple system of image tracking made with Unity. There is an animated avatar with audio source, but I need the users to be able to “start” the animation themselves, only while the image is detected. So I wrote a very simple script attached to a button that starts animation and audio with 2 different functions.
What I need is for the animation is to pause when the image is not tracked (which I am trying to achieve by setting anim.speed to 0) but I also need to the audio clip to keep playing on background.
How can I achieve this?
My code so far:
public void PlayAnimation()
{
//m_animation.Play();
if (m_animation != null && m_animation.gameObject.activeSelf)
{
//m_audioSource.clip = m_audioClip;
m_animation.Play();
//m_audioSource.Play();
}
else if (!m_animation.gameObject.activeSelf)
{
m_clip.speed = 0;
}
}
public void PlaySound()
{
//m_audioSource.Play();
m_audioSource.clip = m_audioClip;
if (m_animation != null && m_animation.gameObject.activeSelf)
{
m_audioSource.Play();
}