I run the sample app. It's working. I need to play audio while cliking green button. I added Audiosource to greenbutton and wrote code. But it's not working. See the attached images/
public class VirtualButtonEventHandler : MonoBehaviour,
IVirtualButtonEventHandler
{
public AudioClip sound;
public AudioSource audiosource;
#region PUBLIC_MEMBER_VARIABLES
/// <summary>
/// The materials that will be set for the teapot model
/// </summary>
public Material[] m_TeapotMaterials;
#endregion // PUBLIC_MEMBER_VARIABLES
#region PRIVATE_MEMBER_VARIABLES
private GameObject mTeapot;
private List<Material> mActiveMaterials;
#endregion // PRIVATE_MEMBER_VARIABLES
#region UNITY_MONOBEHAVIOUR_METHODS
void Start()
{
// Register with the virtual buttons TrackableBehaviour
VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
for (int i = 0; i < vbs.Length; ++i)
{
vbs[i].RegisterEventHandler(this);
}
// Get handle to the teapot object
mTeapot = transform.FindChild("teapot").gameObject;
// The list of active materials
mActiveMaterials = new List<Material>();
}
#endregion // UNITY_MONOBEHAVIOUR_METHODS
#region PUBLIC_METHODS
/// <summary>
/// Called when the virtual button has just been pressed:
/// </summary>
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
Debug.Log("OnButtonPressed");
if (!IsValid())
{
return;
}
// Add the material corresponding to this virtual button
// to the active material list:
switch (vb.VirtualButtonName)
{
case "red":
mActiveMaterials.Add(m_TeapotMaterials[0]);
break;
case "blue":
mActiveMaterials.Add(m_TeapotMaterials[1]);
break;
case "yellow":
mActiveMaterials.Add(m_TeapotMaterials[2]);
break;
case "green":
mActiveMaterials.Add(m_TeapotMaterials[3]);
audiosource.transform.position = transform.position;
audiosource.PlayOneShot(sound);
break;
}
// Apply the new material:
if (mActiveMaterials.Count > 0)
mTeapot.renderer.material = mActiveMaterials[mActiveMaterials.Count - 1];
}
I used same code for my another application. It's working fine. But for virtual button it's not working
Welcome to the joy of programming - context is everything.
If i hide the code for stop the audio the Audioclip is playing, but when i write the code for audioclip play even the audio is not playing. Why?
Not quite sure how you expect anyone else to help you with this. You need to think through this yourself.
I don't have play mode
Why not? If you are using the Trial version this should be available, provided you have a webcam.
But where to find the log
Click where it says "Console"
N