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();
}
}
}