Page 1 of 1

Deactivate object on every dialogue,

Posted: Sun Jun 04, 2023 6:46 pm
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?

Re: Deactivate object on every dialogue,

Posted: Sun Jun 04, 2023 6:52 pm
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;
    }
}