- Home /
Dialogue character emotions system
I've coded so far a dialogue system in which the NPC can to talk the player. There is 2d character portraits but i wish for them to change depending on the sentences being said, ive tried somethings but i am very much a beginner to all this and im learning through asking questions like this
Anyway here is my dialogue manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;
public class DialogueManager : MonoBehaviour {
public Text nameText;
public Text dialogueText;
public GameObject fpsController;
public Animator animator;
public Image Placeholder;
private Queue<string> sentences;
// Use this for initialization
void Start() {
sentences = new Queue<string>();
}
public void StartDialogue(Dialogue dialogue)
{
fpsController.GetComponent<FirstPersonController>().enabled = false;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
animator.SetBool("IsOpen", true);
Debug.Log("Starting conversation with " + dialogue.name);
Placeholder.sprite = dialogue.Actor;
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();
dialogueText.text = sentence;
StartCoroutine(TypeSentence(sentence));
}
IEnumerator TypeSentence (string sentence)
{
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
{
dialogueText.text += letter;
yield return null;
}
}
void EndDialogue()
{
animator.SetBool("IsOpen", false);
Debug.Log("End of Conversation.");
fpsController.GetComponent<FirstPersonController>().enabled = true;
Cursor.visible = false;
}
}
And this is my dialogue script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Dialogue {
public Sprite Actor;
public string name;
[TextArea(3, 10)]
public string[] sentences;
}
There is also a dialogue trigger script which is attached to a collider but that doesn't need changing
And help will be great thanks!
Answer by PhaetonLT · Nov 12, 2020 at 03:14 AM
Three years too late... but anyway :) Looks like the Brackeys script to me :) I put a
public string name;
public string[] sentences;
public Sprite[] dialogueIconList;
On the Dialogue class. And the DialogueManager includes these lines:
public RawImage[] dialogueIcon;
public RawImage facy;
public Sprite[] dialogueIconSprites;
public void StartDialogue (Dialogue dialogue)
dialogueIconSprites = dialogue.dialogueIconList;
DisplayDialogueIcon ();
public void DisplayDialogueIcon ()
{
facy.texture = dialogueIconSprites[index].texture;
}
I am pretty sure if you know how the rest of the script works - you will be able to do the same for the icons :)
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
[SOLVED] Accessing Specific Instance of Variable on Script Across Multiple Objects 0 Answers
Character Collision Trigger Text Message Help! 1 Answer
Multiple Cars not working 1 Answer
Push character away 0 Answers