【问题标题】:Can't change text on hololens无法更改 hololens 上的文本
【发布时间】:2017-04-18 13:20:33
【问题描述】:

我刚开始使用 Hololens,并且一直在使用 Microsoft 网站上的教程中的语音识别脚本。我一直在使用 unity 创建 3D 文本,但是,如果我尝试使用语音命令更改文本不工作!

这是我的以下代码:

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Windows.Speech;
using UnityEngine.UI;

public class VoiceRecognized : MonoBehaviour {
KeywordRecognizer kr = null;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();

// Use this for initialization
public Text name_text;

private string testName = "Drop";
void begin () {

    keywords.Add("Change", () =>
    {
        this.BroadcastMessage("OnReset");

    });

    kr = new KeywordRecognizer(keywords.Keys.ToArray());

    kr.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
    kr.Start();
}
public void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
    System.Action keywordAction;
    if (keywords.TryGetValue(args.text, out keywordAction))
    {
        keywordAction.Invoke();
    }
}
// Update is called once per frame
void Update () {
}
}

另一个程序在听到“更改”时更改文本。

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class ChangeText : MonoBehaviour {
public Text name_text;


void Start()
{

}
void OnReset()
{

    name_text.text = "Change"; 
}
}

在这段代码中,我使用语音识别脚本将初始文本“Hello World”更改为“Change”。我不确定我的 Unity 是否有问题,但我目前正在关注微软在他们的教程中所做的一切。

【问题讨论】:

  • 1) 您确定语音命令正在被识别吗? 2) ChangeText 类是否与voiceRecognized 类位于同一对象上?
  • 谢谢!它不在更改文本类中
  • begin 方法在哪里调用?
  • 您是否检查过您是否能够在ChangeText 组件中引用您的文字游戏对象?

标签: c# unity3d hololens


【解决方案1】:

尝试在单击按钮时调用相同的方法,看看是否有效。您可以使用 Debug.Log 来查看您的方法是否被语音命令调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    相关资源
    最近更新 更多