Start quest dialog with space key

Announcements, support questions, and discussion for Quest Machine.
Post Reply
dkrusenstrahle
Posts: 39
Joined: Sat Apr 20, 2024 7:03 pm

Start quest dialog with space key

Post by dkrusenstrahle »

Hello,
Currently all Quest interactions are started by colliding with the NPC trigger collider. I want to only start the process when I stand close to the NPC (perhaps when colliding) and the.hit for example space key on the keyboard.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Start quest dialog with space key

Post by Tony Li »

Hi,

You can use your preferred interaction system/script for that. Your interaction system/script just needs to call the QuestGiver's StartDialogueWithPlayer() method.

For example, if you're using the Dialogue System for Unity, it has a "Proximity Selector" interaction system. Using this system, you can put a "Usable" component on the NPC and configure its OnUse() method to call QuestGiver.StartDialogueWithPlayer().

If you're using any other interaction system, you'd set it up similarly.
dkrusenstrahle
Posts: 39
Joined: Sat Apr 20, 2024 7:03 pm

Re: Start quest dialog with space key

Post by dkrusenstrahle »

Thank you!

If anyone wonders how I made it work is that I added this script to the player:

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;

public class CharacterQuestGiverActivation : MonoBehaviour
{
    private QuestGiver currentQuestGiver;

    private void Update()
    {
        if (currentQuestGiver != null && (Input.GetKeyDown(KeyCode.E)))
        {
            currentQuestGiver.StartDialogueWithPlayer();
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        QuestGiver questGiver = other.GetComponent<QuestGiver>();
        if (questGiver != null)
        {
            currentQuestGiver = questGiver;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.GetComponent<QuestGiver>() != null)
        {
            currentQuestGiver = null;
        }
    }
}

User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Start quest dialog with space key

Post by Tony Li »

Thanks for sharing!
Post Reply