Log in or register to post comments

Adding Audio C# Script

June 22, 2018 - 8:18pm #1

Hi, 

I'm trying to add Audio to an AR project. But I get a compiler error for the script suggested in previous posts.

Any help would be greatly appreciated.

(script used from https://developer.vuforia.com/forum/faq/unity-how-can-i-play-audio-when-targets-get-detected)

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;



public class PlayAudio2 : 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)

        {

            // Play audio when target is found

            audio.Play();

        }

        else

        {

            // Stop audio when target is lost

            audio.Stop();

        }

    }  

}

Log in or register to post comments