0

I'm new to Unity and my problem seems very simple but I can't find an answer online. I'm trying to implement VoiceSDK (speech recognition) on a Oculus Quest. There's a event called OnError(string, string) automatically called by Wit when an error occurs. But using the inspector, I can't make these strings displayed in a TextMeshPro. I can only with event giving 1 parameter. The only functions I can use are "BroadcastMessage" or "SendMessage"...

Event image

derHugo
  • 83,094
  • 9
  • 75
  • 115
hyonarge
  • 33
  • 1
  • 4
  • You will need a custom component which handles these via a method like `public void HandleError(string a, string b) { ... }` and forwards them to your text components – derHugo Feb 21 '22 at 16:03

1 Answers1

0

As said you can't directly set the Text.text via the event.

You will need a dedicated component on your Texts like e.g.

[RequireComponent (typeof (Text))]
public class ErrorHandler : MonoBehaviour
{
    [SerializeField] private Text _text;

    void Awake ()
    {
        if(!_text) _text = GetComponent<Text>();
    }

    public void HandleError(string a, string b)
    {
        _text.text = a; // or b?
    }
}

And then in the drop-down you rather select this HandleError method from the dynamic ones.


Or alternatively you do the se but on this object itself and have a component like

public class ErrorHandler : MonoBehaviour
{
    [SerializeField] private Text buttonText;
    [SerializeField] private Text logText;

    public void HandleError(string a, string b)
    {
        buttonText.text = a;
        logText.text = b;
    }
}

and just reference your two texts accordingly

derHugo
  • 83,094
  • 9
  • 75
  • 115