Display name when condition is met

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
chud575
Posts: 50
Joined: Thu May 11, 2017 10:57 am

Display name when condition is met

Post by chud575 »

Howdy,

Is there a way to keep the name of the conversant hidden until a condition is met? (You know, like asking "What's your name?")
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Display name when condition is met

Post by Tony Li »

Hi,

You'll need to use a script. Let's say each actor in your database has a custom Boolean field named "Known" that starts false. When the NPC reveals his name, set it true. You can use the Lua wizard in that dialogue entry node to set the field. The script below (written for Unity UI) sets the portrait name's color alpha to solid or invisible based on the value of this field.

ControlPortraitName.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ControlPortraitName : MonoBehaviour {

    void OnConversationLine(Subtitle subtitle) {
        if (!subtitle.speakerInfo.isNPC) return;        
        var actorName = subtitle.speakerInfo.nameInDatabase;
        var known = DialogueLua.GetActorField(actorName, "Known").AsBool;
        var dialogueUI = DialogueManager.DialogueUI as UnityUIDialogueUI;
        var portraitName = dialogueUI.dialogue.npcSubtitle.portraitName;
        var color = portraitName.color;
        portraitName.color = new Color(color.r, color.g, color.b, known ? 1 : 0);
    }
}
Post Reply