[Help] Enabling movement of the Gameobject only after an Input Command (Voice)

Hi all,

I am a novice here, still in the learning phase. Request all to kindly help with it, it’ll be appreciated!
I have a GameObject and a movement script attached to it. It starts moving as soon as I press the play button in the Editor.I want it to start moving only after getting a voice command. I have added the Holotoolkit SDK and have all the project and scene settings applied as mentioned in the MRTK docs. I have a simple Keyword class(which as of now just does Scaling up and down), wherein I want to add and call for movement of the GameObject. Attaching both the scripts below( Movement and Keyword).

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

public class DiscMove : MonoBehaviour {

    public float speed = 1.0F;
    private float startTime;
    private float journeyLength;
    public float smooth = 5.0F;

    public Transform[] waypoints;

    private Transform startMarker, endMarker;
    private int currentStartPoint;
    void Start()
    {
            currentStartPoint = 0;
            SetPoints();
           
    }
    void SetPoints()
    {
      
        startMarker = waypoints[currentStartPoint];
        if(currentStartPoint + 1 < waypoints.Length)
        {
            endMarker = waypoints[currentStartPoint + 1];
        }
      
        startTime = Time.time;
        journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
    }
    void Update()
    {
        float distCovered = (Time.time - startTime) * speed;
        float fracJourney = distCovered / journeyLength;
        transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
        if (fracJourney >= 1f && currentStartPoint + 1 < waypoints.Length)
        {
            currentStartPoint++;
            SetPoints();
        }
    }
  
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HoloToolkit.Unity.InputModule.Tests
{
    public class VoiceInputKeyword : MonoBehaviour, ISpeechHandler
    {

        public void ZoomIn()
        {
            gameObject.transform.localScale += 0.05f * gameObject.transform.localScale;
        }

        public void ZoomOut()
        {
            gameObject.transform.localScale -= 0.05f * gameObject.transform.localScale;
        }

       

        public void OnSpeechKeywordRecognized(SpeechEventData eventData)
        {
            ZoomIn();
            ZoomOut();

        }
    }
}

Is the OnSpeechKeywordRecognised method being called? If so, it wouldn’t do anything because the ZoomIn call is immediately followed by ZoomOut.

Anyway, you need to change what method is called based on the eventData parameter. You can get the text that was recognised with eventData.RecognizedText. It will also need a reference to the DiscMove class to make it do anything. Something like this:

public void OnSpeechKeywordRecognized(SpeechEventData eventData)
{
    switch(eventData.RecognizedText)
    {
        case "move disc":
            disc.moveDisc = true;
            break;
        case "some other command":
            // different behaviour
            break;
        default:
            print("Text not handled: '" + eventData.RecognizedText + "'");
    }
}

And in the DiscMove class:

    public bool move;
    void Update()
    {
        if(move)
        {
            float distCovered = (Time.time - startTime) * speed;
            float fracJourney = distCovered / journeyLength;
            transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
            if (fracJourney >= 1f && currentStartPoint + 1 < waypoints.Length)
            {
               currentStartPoint++;
               SetPoints();
            }
        }
    }