Start dialogue on button press
Start dialogue on button press
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
Hi,
You can write a script that listens for the "J" key and starts a conversation. Example (using the built-in input manager):
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
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
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:
to:
Code: Select all
DialogueManager.StartConversation(conversation);
Code: Select all
var player = GameObject.FindWithTag("Player");
DialogueManager.StartConversation(conversation, player.transform);
Re: Start dialogue on button press
Yep, it worked, thanks!
Re: Start dialogue on button press
Glad to help!