【问题标题】:How to play sound only when marker is detected in Unity Vuforia如何仅在 Unity Vuforia 中检测到标记时播放声音
【发布时间】:2021-12-14 17:11:36
【问题描述】:

我正在使用 Vuforia 在 Unity 中实现一个 AR Android 应用。我试图在检测到标记后立即播放声音,然后在未检测到标记时停止声音。当我目前在手机上构建和运行应用程序时,声音会直接播放,而我无需跟踪目标,这不是我想要的。

这是我的 C# 代码:

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Vuforia;

public class Sound : DefaultTrackableEventHandler
{

    protected override void OnTrackingFound()
    {

        base.OnTrackingFound();
        AudioSource[] sounds = GetComponentsInChildren<AudioSource>();

        sounds[0].Play();
    }

    protected override void OnTrackingLost()
    {
        base.OnTrackingLost();

        AudioSource[] sounds = GetComponentsInChildren<AudioSource>();

        sounds[0].Stop();


    }

} 


有人知道为什么这段代码 sn-p 不起作用吗?如果是这样,我可能会错过什么?

谢谢。

【问题讨论】:

  • 可以分享控制台日志吗?

标签: c# android unity3d audio vuforia


【解决方案1】:

据我所知,无论是否找到跟踪,您都必须在更新功能中给出它。如果找到跟踪,就会播放声音。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 2013-06-28
    相关资源
    最近更新 更多