public void playSubtitleForTime(string text, float duration, OnSubtitleFinished completionFunction)
 {
     if (currentRoutine != null)
     {
         StopCoroutine(currentRoutine);
     }
     currentRoutine = StartCoroutine(playSubtitleForTimeAsync(text, duration, completionFunction));
 }
    private IEnumerator playSubtitleForTimeAsync(string text, float duration, OnSubtitleFinished completionFunction)
    {
        subtitleText.text = text;
        subtitleCanvas.SetActive(true);

        yield return new WaitForSeconds(duration);

        subtitleCanvas.SetActive(false);
        subtitleText.text = "";

        if (completionFunction != null) {
            completionFunction();
        }
    }
    private IEnumerator playSubtitleForTimeAsync(string text, float duration, OnSubtitleFinished completionFunction)
    {
        subtitleText.text = text;
        if (subtitleCanvas != null)
        {
            subtitleCanvas.SetActive(true);
        }

        yield return(new WaitForSeconds(duration));

        if (subtitleCanvas != null)
        {
            subtitleCanvas.SetActive(false);
        }
        subtitleText.text = "";

        if (completionFunction != null)
        {
            completionFunction();
        }
    }
 public void playSubtitleForTime(string text, float duration, OnSubtitleFinished completionFunction)
 {
     StartCoroutine(playSubtitleForTimeAsync(text, duration, completionFunction));
 }