- Home /
Question by
rebourtino · Mar 21 at 05:10 PM ·
dialogue
Im a trying to add a animation to my text during the dialogue
Im a trying to add a animation to my text during the dialogue. My question is:
(YOUR QUESTION) ?
DialogManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogManager : MonoBehaviour
{
public Image actorImage;
public Text actorName;
public Text messageText;
public RectTransform backgroundBox;
public AudioSource audiosource;
public Animator DialoguAnimator;
public Animator AvatarAnimator;
Message[] currentMessages;
Actor[] currentActors;
int activeMessage = 0;
public static bool IsActive = false;
public void OpenDialogue(Message[] messages, Actor[] actors)
{
currentMessages = messages;
currentActors = actors;
activeMessage = 0;
IsActive = true;
DialoguAnimator.SetBool("DialoguOpen",true);
AvatarAnimator.SetBool("AvatarOpen",true);
//Debug.Log("Started Conversation! Loaded message : " + messages.Length);
DisplayMessage();
}
void DisplayMessage()
{
Message messageToDisplay = currentMessages[activeMessage];
messageText.text = messageToDisplay.message;
Actor actorToDisplay = currentActors[messageToDisplay.actorId];
actorName.text = actorToDisplay.name;
actorImage.sprite = actorToDisplay.sprite;
}
IEnumerator TypeSentence (string messageToDisplay)
{
audiosource.Play();
messageText.text = "";
foreach (char letter in messageToDisplay.message.ToCharArray())
{
messageText.text += letter;
yield return new WaitForSeconds(0.05f);
}
audiosource.Stop();
}
public void NextMessage()
{
activeMessage++;
if (activeMessage < currentMessages.Length)
{
DisplayMessage();
}
else
{
DialoguAnimator.SetBool("DialoguOpen",false);
AvatarAnimator.SetBool("AvatarOpen",false);
//Debug.Log("End of Conversation");
IsActive = false;
}
}
void Update()
{
if (Input.GetKeyDown("joystick button 1") && IsActive == true)
{
NextMessage();
}
}
}
Comment
Your answer
Follow this Question
Related Questions
string problem 2 Answers
Dialogue strategy? 0 Answers
How to make dialog window? 1 Answer
VR RPG like dialogue system 1 Answer