Page 1 of 1

Call Conversation By Code

Posted: Wed Oct 02, 2024 11:10 am
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();
    }

Re: Call Conversation By Code

Posted: Wed Oct 02, 2024 12:05 pm
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>);
    }
}