Call Conversation By Code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Littlenorwegians
Posts: 32
Joined: Sun Aug 04, 2024 3:06 pm

Call Conversation By Code

Post by Littlenorwegians »

Hello!

I need a bit of help as this has to do with the Dialogue System interacting with other pieces of game code.
What I need essentially is just the right syntax, I believe, to set up the database, the UI that's gonna be used (Remember, I have two different ones) AND what conversation to start.

Hope this is fairly easy :)
(Pseudo code)

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class PhonecallTrigger : MonoBehaviour
{
    public GameObject Player; 
    public UI TheUIToUse;
    public Conversation PhoneCallToCall;

    // Start is called before the first frame update

    public void OnTriggerEnter(Collider other)
    {
        //Bunch of code here about disabling other systems etc, etc
	DialogueManager.UI = TheUiToUse;
        PhoneCallToCall.start();
    }
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call Conversation By Code

Post by Tony Li »

Hi,

You could configure a Dialogue System Trigger on the phone GameObject and call its OnUse() method:

Code: Select all

public void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        GetComponent<DialogueSystemTrigger>().OnUse(other.transform);
    }
}
Or you could omit the Dialogue System Trigger entirely and start the conversation directly in C# Code:

Code: Select all

[ConversationPopup(true)] public string conversationTitle;
public GameObject dialogueUI;

public void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        DialogueManager.StartConversation(conversationTitle, other.transform, this.transform, -1, dialogueUI.GetComponent<IDialogueUI>);
    }
}
Post Reply