How to keep the sound when reading an augmented reality

0

I have the following situation. I am reading a pattern with RA with vuforia . At the moment of reading the pattern, it begins to play a sound while I am reading but if I stop reading the pattern the sound stops. My question is the following there is some way that once the sound begins to play does not stop until it reaches the end. Then I leave the code.

using UnityEngine;
using Vuforia;

public class reproduccionAudio : MonoBehaviour, ITrackableEventHandler
{

 private TrackableBehaviour mTrackableBehaviour;

        void Start(){
            mTrackableBehaviour = GetComponent<TrackableBehaviour>();
            if (mTrackableBehaviour){
                mTrackableBehaviour.RegisterTrackableEventHandler(this);
            }
        }

        public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus){         

            if (newStatus == TrackableBehaviour.Status.DETECTED ||
                newStatus == TrackableBehaviour.Status.TRACKED ||
                newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED  )
            {
            GetComponent<AudioSource>().Play();
        }else{
            GetComponent<AudioSource>().Stop();
        }
    }
 }

Thanks

    
asked by Yoel Rodriguez 09.03.2018 в 17:26
source

1 answer

1

So that you do not stop playing your Audiosource you just have to comment on the path else of your code since it is activated when you stop doing the action of the pattern.

public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus){         

    if (newStatus == TrackableBehaviour.Status.DETECTED ||
        newStatus == TrackableBehaviour.Status.TRACKED ||
        newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED  )
    {
        GetComponent<AudioSource>().Play();
    }
    //else{
    //    GetComponent<AudioSource>().Stop();
    //}
}
    
answered by 09.03.2018 / 23:08
source