How to adapt Voice Recognition Script to my project?

To begin with, I’m fairly new to code and I’m unsure how to adapt the code below to achieve my desires functionalities.

I’m want to add a function to: turn lights on/off, switching between cameras. However, I also would like to target my in-game character (not 2d image), to do something when inside a trigger. Making my player the target is what confuses me the most, as I’ve tried to change the “public Image target” to “public Object target”, which doesn’t seem to be the solution :confused:

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

public class SpeechRecognitionEngine : MonoBehaviour
{
public string keywords = new string { “up”, “down”, “left”, “right” };
public ConfidenceLevel confidence = ConfidenceLevel.Medium;
public float speed = 1;

public Text results;
public Image target;

protected PhraseRecognizer recognizer;
protected string word = "right";

private void Start()
{
    if (keywords != null)
    {
        recognizer = new KeywordRecognizer(keywords, confidence);
        recognizer.OnPhraseRecognized += Recognizer_OnPhraseRecognized;
        recognizer.Start();
    }
}

private void Recognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
    word = args.text;
    results.text = "You said: <b>" + word + "</b>";
}

private void Update()
{
    var x = target.transform.position.x;
    var y = target.transform.position.y;

    switch (word)
    {
        case "up":
            y += speed;
            break;
        case "down":
            y -= speed;
            break;
        case "left":
            x -= speed;
            break;
        case "right":
            x += speed;
            break;
    }

    target.transform.position = new Vector3(x, y, 0);
}

private void OnApplicationQuit()
{
    if (recognizer != null && recognizer.IsRunning)
    {
        recognizer.OnPhraseRecognized -= Recognizer_OnPhraseRecognized;
        recognizer.Stop();
    }
}

}

Hi @Chikzter , when i used this code me getting an error

Error: there already is a keyword recognizer with “up” as one of its keywords
UnityEngine.Windows.Speech.KeywordRecognizer:.ctor(String, ConfidenceLevel)
SpeechRecognition:Start()

Please help.