Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dialogue system with characters face that changes depending on the character [solved]

Discussion in 'Scripting' started by Felipe_Schluepmann, Mar 8, 2021.

  1. Felipe_Schluepmann

    Felipe_Schluepmann

    Joined:
    Jan 12, 2021
    Posts:
    14
    Hi I'm trying to make a dialogue system that shows an image of the character's face, I'm using the brackets tutorial on how to make a Dialoguesystem, so I have a DialogueManager script, a Dialogue script, and a DialogueTrigger Script, I made an additional script in an image in the UI (which is where the face is supposed to be) which is just to reference the sprite used in the Dialogue Script, but I have no idea on how to actually make the image change depending on the sprite I place on the Dialogue is it even possible to do that?

    I know its wrong but here are my Dialogue script and my ChangeFace Script

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. [System.Serializable]
    8. public class Dialogue
    9. {
    10.     public string name;
    11.  
    12.     public Sprite face;
    13.  
    14.     [TextArea(3, 10)]
    15.     public string[] sentences;
    16.  
    17. }
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class ChangeFace : MonoBehaviour
    8. {
    9.  
    10.     public Dialogue faceChange;
    11.  
    12.     public Image image;
    13.  
    14.     private void Update()
    15.     {
    16.         faceChange.face = image;
    17.     }
    18. }
     
  2. Felipe_Schluepmann

    Felipe_Schluepmann

    Joined:
    Jan 12, 2021
    Posts:
    14
    Just figured it out and it worked just had to change the interaction object so in there when a person talks the image is changed