Deactivate object on every dialogue,

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ujuj04
Posts: 30
Joined: Sun May 21, 2023 7:34 pm

Deactivate object on every dialogue,

Post by ujuj04 »

Hey, I have a time switch mechanic (magic clock activates when RMB is pressed) that is loading a different scene. It works during dialogues. Is there a way I can deactivate this object(magic clock) during all dialogues? Initially my idea was to make a script that would deactivate it on conversation start and then activate back on conversation end, but I have to many NPCs to edit this. Is there a smart way to fix this?
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Deactivate object on every dialogue,

Post by Tony Li »

If you use the C# events DialogueManager.instance.conversationStarted and conversationEnded, the script can be anywhere. For example, if your magic clock GameObject is not a conversation actor or conversant, and if it has a script named MagicClock, you could disable MagicClock by adding this script to the GameObject:

DisableMagicClockDuringConversations.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class DisableMagicClockDuringConversations : MonoBehaviour
{
    void OnEnable()
    {
        DialogueManager.instance.conversationStarted += OnConversationStarted;
        DialogueManager.instance.conversationEnded += OnConversationEnded;
    }
    
    void OnDisable()
    {
        DialogueManager.instance.conversationStarted -= OnConversationStarted;
        DialogueManager.instance.conversationEnded -= OnConversationEnded;
    }
    
    void OnConversationStarted(Transform actor)
    {
        GetComponent<MagicClock>().enabled = false;
    }
    
    void OnConversationEnded(Transform actor)
    {
        GetComponent<MagicClock>().enabled = true;
    }
}
Post Reply