Page 1 of 1

Start dialogue on button press

Posted: Tue Jun 06, 2023 5:45 pm
by ujuj04
I want a dialogue to appear on a button press. My player has a companion that is following them all the time. I want to make the player to be able to talk to then whenever and wherever by pressing "J". How do I do that? Thanks in advance. However, I want all the other dialogues to be used with "E" like they are already.

Re: Start dialogue on button press

Posted: Tue Jun 06, 2023 7:20 pm
by Tony Li
Hi,

You can write a script that listens for the "J" key and starts a conversation. Example (using the built-in input manager):

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CompanionConversation : MonoBehaviour
{
    [ConversationPopup(true)] public string conversation;
    
    void Update()
    {
        if (!DialogueManager.isConversationActive && Input.GetKeyDown(KeyCode.J))
        {
            DialogueManager.StartConversation(conversation);
        }
    }
}

Re: Start dialogue on button press

Posted: Tue Jun 06, 2023 7:39 pm
by ujuj04
Hey, thanks for the help. However, I also deactivate the player capsule in my dialogue system events. Can I do it in code for this particular conversation?

Re: Start dialogue on button press

Posted: Tue Jun 06, 2023 7:46 pm
by Tony Li
Yes. If the conversation can't automatically find the player -- see Character GameObject Assignments -- then you can manually pass in the player's transform. For example, change this line:

Code: Select all

DialogueManager.StartConversation(conversation);
to:

Code: Select all

var player = GameObject.FindWithTag("Player");
DialogueManager.StartConversation(conversation, player.transform);

Re: Start dialogue on button press

Posted: Wed Jun 07, 2023 12:28 am
by ujuj04
Yep, it worked, thanks!

Re: Start dialogue on button press

Posted: Wed Jun 07, 2023 7:14 am
by Tony Li
Glad to help!