Page 1 of 1
Start quest dialog with space key
Posted: Mon Apr 22, 2024 7:15 pm
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.
Re: Start quest dialog with space key
Posted: Mon Apr 22, 2024 8:24 pm
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.
Re: Start quest dialog with space key
Posted: Tue Apr 23, 2024 5:56 am
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;
}
}
}
Re: Start quest dialog with space key
Posted: Tue Apr 23, 2024 8:12 am
by Tony Li
Thanks for sharing!