[HOWTO] How To: Add Greeting Sound to Quest Giver
Posted: Fri Dec 27, 2024 11:36 am
Quest Machine uses its Message System to send a "Greet" message whenever the player greets a Quest Giver. You could use a Quest Machine Message Events component to handle this event, but it's probably simpler to just add this script to the Quest Giver and assign an audio clip:
QuestGiverGreetingSound.cs
QuestGiverGreetingSound.cs
Code: Select all
using UnityEngine;
using PixelCrushers;
using PixelCrushers.QuestMachine;
public class QuestGiverGreetingSound : MonoBehaviour, IMessageHandler
{
public AudioClip greetingAudioClip;
private void OnEnable()
{
var questGiver = GetComponent<QuestGiver>();
MessageSystem.AddListener(this, QuestMachineMessages.GreetMessage, questGiver.id);
}
private void OnDisable()
{
MessageSystem.RemoveListener(this);
}
public void OnMessage(MessageArgs messageArgs)
{
AudioSource.PlayClipAtPoint(greetingAudioClip, transform.position);
}
}