在学会利用U3d处理音频之后,看下面的教程。
1、
虚拟按钮
结合Vuforia 虚拟按钮制作教程,在该方法下添加对应事件。
复制代码
/// <summary>
/// Called when the virtual button has just been pressed:
/// </summary>
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
{
if (!button_audio.isPlaying) {
button_audio.Play();
}
if (button_audio.isPlaying) {
button_audio.volume=1;
}
Debug.Log("OnButtonPressed::" + vb.VirtualButtonName);
// Add the material corresponding to this virtual button
// to the active material list:
switch (vb.VirtualButtonName)
{
case "one":
//myObject.transform.animation.Play();
myObject.transform.animation.Play("Take 4");
labelname = "one -> Run!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
if (button_audio.isPlaying) {
button_audio.volume=1;
}
break;
case "two":
myObject.transform.animation.Play("Take 002");
labelname = "two -> Nothing!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
break;
case "three":
//myObject.transform.animation.Play("Take 4");
myObject.transform.animation.Play();
labelname = "three -> Stand!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
break;
case "four":
myObject.transform.animation.Play("Take 5");
labelname = "four -> Hello!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
break;
}
}
2、
模型出现
在
DefaultTrackableEventHandler
脚本中,
OnTrackingFoun
d方法触发。
复制代码
private void OnTrackingFound()
{
if (!baymax_audio.isPlaying) {
baymax_audio.Play ();
}
if (baymax_audio.isPlaying) {
baymax_audio.volume = 60;
}
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
}
3、按钮事件
总结:
1、
和Unity3D播放音频处理方式一样
if
(!button_audio.isPlaying) {
button_audio.Play();
}
2、对AR场景中,音效触发事件的不同
在学会利用U3d处理音频之后,看下面的教程。
1、
虚拟按钮
结合Vuforia 虚拟按钮制作教程,在该方法下添加对应事件。
复制代码
/// <summary>
/// Called when the virtual button has just been pressed:
/// </summary>
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
{
if (!button_audio.isPlaying) {
button_audio.Play();
}
if (button_audio.isPlaying) {
button_audio.volume=1;
}
Debug.Log("OnButtonPressed::" + vb.VirtualButtonName);
// Add the material corresponding to this virtual button
// to the active material list:
switch (vb.VirtualButtonName)
{
case "one":
//myObject.transform.animation.Play();
myObject.transform.animation.Play("Take 4");
labelname = "one -> Run!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
if (button_audio.isPlaying) {
button_audio.volume=1;
}
break;
case "two":
myObject.transform.animation.Play("Take 002");
labelname = "two -> Nothing!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
break;
case "three":
//myObject.transform.animation.Play("Take 4");
myObject.transform.animation.Play();
labelname = "three -> Stand!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
break;
case "four":
myObject.transform.animation.Play("Take 5");
labelname = "four -> Hello!";
if (!button_audio.isPlaying) {
button_audio.Play();
}
break;
}
}
2、
模型出现
在
DefaultTrackableEventHandler
脚本中,
OnTrackingFoun
d方法触发。
复制代码
private void OnTrackingFound()
{
if (!baymax_audio.isPlaying) {
baymax_audio.Play ();
}
if (baymax_audio.isPlaying) {
baymax_audio.volume = 60;
}
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
}
3、按钮事件
总结:
1、
和Unity3D播放音频处理方式一样
if
(!button_audio.isPlaying) {
button_audio.Play();
}
2、对AR场景中,音效触发事件的不同