daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.Windows.Speech;
  6.  
  7. public class SpeechControl : MonoBehaviour {
  8.  
  9.     public string fireCommand = "fire";
  10.     public string resetCommand = "reset";
  11.  
  12.     private KeywordRecognizer keywordRecognizer;
  13.  
  14.     void Start()
  15.     {
  16.         // Set up Keyword Recognizer to register our assigned voice commands
  17.         keywordRecognizer = new KeywordRecognizer(new[] { fireCommand, resetCommand });
  18.         keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
  19.         keywordRecognizer.Start();
  20.     }
  21.  
  22.     // Called whenever a voice command is recognised
  23.     private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
  24.     {
  25.         string cmd = args.text;
  26.  
  27.         // If user said "fire", shoot arrow from Bow
  28.         if (cmd == fireCommand)
  29.         {
  30.             GetComponent<Bow>().Shoot();
  31.         }
  32.  
  33.         // If user said "reset", reload the Unity scene to start from the beginning
  34.         else if (cmd == resetCommand)
  35.         {
  36.             SceneManager.LoadSceneAsync(0, LoadSceneMode.Single);
  37.         }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top