Top.Mail.Ru
Ответы

Помогите решить проблему

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class DialogueManager : MonoBehavior

{

public Text dialogueText;

public Text nameText;

public Animator boxAnim;

public Animator startAnim;

private Queue<string> sentences;

private void Start()

{

sentences = new Queue<string>();

}

public void StartDialogue(Dialogue dialogue)

{

boxAnim.SetBool("boxOpen", true);

startAnim.SetBool("startOpen", false);

nameText.Text = dialogue.name;

sentences.Clear();

foreach (string sentence in dialogue.sentences)

{

sentences.Enqueue(sentence);

}

DisplayNextSentence();

}

public void DisplayNextSentence()

{

if (sentences.Count == 0)

{

EndDialogue();

return;

}

string sentence = sentences.Dequeue();

StopAllCoroutines()

StartCoroutine(TypeSentence));

}

IEnumerator TypeSentence(string sentence)

{

dialogueText.Text = "";

foreach (char letter in sentence.ToCharArray())

{

dialogueText.Text += letter;

yield return null;

}

}

public EndDialogue()

{

boxAnim.SetBool("boxOpen", false);

}

}


По дате
По рейтингу
Аватар пользователя
Мастер

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DialogueManager : MonoBehaviour
{
    public Text dialogueText;
    public Text nameText;
    public Animator boxAnim;
    public Animator startAnim;

    private Queue<string> sentences;

    private void Start()
    {
        sentences = new Queue<string>();
    }

    public void StartDialogue(Dialogue dialogue)
    {
        boxAnim.SetBool("boxOpen", true);
        startAnim.SetBool("startOpen", false);

        nameText.text = dialogue.name;

        sentences.Clear();
        foreach (string sentence in dialogue.sentences)
        {
            sentences.Enqueue(sentence);
        }

        DisplayNextSentence();
    }

    public void DisplayNextSentence()
    {
        if (sentences.Count == 0)
        {
            EndDialogue();
            return;
        }

        string sentence = sentences.Dequeue();

        StopAllCoroutines();

        StartCoroutine(TypeSentence(sentence));
    }

    IEnumerator TypeSentence(string sentence)
    {
        dialogueText.text = "";
        foreach (char letter in sentence.ToCharArray())
        {
            dialogueText.text += letter;
            yield return null;
        }
    }

    public void EndDialogue()
    {
        boxAnim.SetBool("boxOpen", false);
    }
}