[HOWTO] How To: Add Greeting Sound to Quest Giver

Announcements, support questions, and discussion for Quest Machine.
Post Reply
User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Add Greeting Sound to Quest Giver

Post by Tony Li »

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

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);
    }
}
Post Reply