Ejemplo n.º 1
0
    IEnumerator Speaking(string speech, string speaker, bool additive, float textSpeed = 3.5f)
    {
        SpeechPanel.SetActive(true);
        targetSpeech = speech;

        if (!additive)
        {
            SpeechText.text = "";
        }
        else
        {
            targetSpeech = SpeechText.text + speech;
        }
        SpeakerNameText.text = speaker;

        float lettersToWriteInNextFrame = 0;

        while (SpeechText.text != targetSpeech)
        {
            float lettersToWriteInFrame = textSpeed;
            while (lettersToWriteInFrame > 1)
            {
                SpeechText.text += targetSpeech[SpeechText.text.Length];
                lettersToWriteInFrame--;
                if (SpeechText.text == targetSpeech)
                {
                    break;
                }
            }
            lettersToWriteInNextFrame += lettersToWriteInFrame;
            yield return(new WaitForEndOfFrame());
        }
        displayedSpeech = SpeechText.text;
        StopSpeaking();
    }
    IEnumerator Speaking(string speech, bool additive, string speaker = "")
    {
        SpeechPanel.SetActive(true);                      //make speech panel visible and active
        SpeakerNameText.text = determineSpeaker(speaker); //temporary
        targetSpeech         = speech;

        //check if text is additive or overriding
        if (!additive)
        {
            DialogueText.text = "";
        }
        else
        {
            targetSpeech = DialogueText.text + targetSpeech;
        }

        //reset at the start of new text
        waitingForUserInput = false;

        //while the text in the dialogue box isn't the finished text add text
        while (DialogueText.text != targetSpeech)
        {
            //take the next letter from target speech by counting how many letters have been added to dialogue text already
            DialogueText.text += targetSpeech[DialogueText.text.Length];
            yield return(new WaitForEndOfFrame()); //wait until end of frame
        }

        //once text is finished wait for user to continue
        waitingForUserInput = true;

        while (waitingForUserInput)
        {
            yield return(new WaitForEndOfFrame());
        }
        StopSpeaking();
    }
 ///<summary>
 ///stop all speech and close dialogue panel
 ///</summary>
 public void Close()
 {
     StopSpeaking();
     SpeechPanel.SetActive(false);
 }