Skip to content

Instantly share code, notes, and snippets.

@jazzyjackson
Last active June 30, 2017 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzyjackson/4c5882591c8abb8ec69ac0f8c788327d to your computer and use it in GitHub Desktop.
Save jazzyjackson/4c5882591c8abb8ec69ac0f8c788327d to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Windows.Speech;
public class cubeFollow : MonoBehaviour {
private string mode = "none";
// Use this for initialization
KeywordRecognizer keywordRecognizer = null;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
// Use this for initialization
void Start()
{
keywords.Add("bigger", () => {
mode = "grow";
});
keywords.Add("smaller", () => {
mode = "shrink";
});
keywords.Add("stop", () => {
mode = "none";
});
keywords.Add("pick up", () => {
mode = "follow";
});
keywords.Add("place", () => {
mode = "none";
});
// Tell the KeywordRecognizer about our keywords.
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
// Register a callback for the KeywordRecognizer and start recognizing!
keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
keywordRecognizer.Start();
}
private 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 () {
switch(mode) {
case "follow":
transform.position = Camera.main.transform.position + Camera.main.transform.forward * 5;
break;
case "grow":
transform.localScale *= 1.01f;
break;
case "shrink":
transform.localScale *= 0.99f;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment