Destroying a trigger disconnected from an object

Hello,
I’m a new Unity user. I’m running into a problem with objects and triggers, and I was wondering if someone might have some advice? Here’s the situation:

I have a destructible game object, which of course must have its own collider for the player’s shot to destroy it. I also have a separate area trigger near this object (with its own collider) that triggers a conversation if the player has a variable when the player moves into it. Normally, the player would approach the object, the conversation would play, and then the player would destroy the object.

However, the problem occurs when the player doesn’t have the variable to trigger the conversation. The player might still destroy the object, later get the variable, and then move into that area again and trigger the conversation about the object that…isn’t there.

So, I want to figure out how to either destroy the conversation trigger when the object is destroyed, or somehow disable the conversation trigger when the object is destroyed. I can’t attach the conversation trigger to the destructible object because they then share the larger collider, which means the player can shoot at the object, miss, but hit the larger conversation trigger and destroy the object–which feels weird.

Any ideas?

So I guess there are many ways to go about this but to me it sounds like you need some kind of system to keep track of if certain conditions (certain variable, object is not destroyed) are met before a certain event can trigger (the conversation).

It might be beneficial for you to create a class that can evaluate these things on the fly and then attach it to the OnTrigger code which runs when the player enters the conversation trigger. Something in the likes of:

using System.Linq;

public class ConditionsChecker
{
    public EventHandler AllConditionsMet;

    private List<Condition> Conditions;

    public void AddCondition(Condition condition)
    {
        condition.ConditionMetChanged += OnConditionChanged;
        Conditions.Add(condition);  
    }

    public bool AreAllConditionsMet()
    {
        return Conditions.All(condition => condition.ConditionMet)
    }

    private void OnConditionChanged(object sender, bool isMet)
    {
        if (AllConditionsMet())
            AllConditionsMet?.Invoke(this, null);
    }
}

public class Condition
{
    private bool ConditionIsMet;

    public EventHandler<bool> ConditionMetChanged;

    public void SetCondition(bool isMet)
    {
        ConditionIsMet = isMet;
        ConditionMetChanged?.Invoke(this, isMet);
    }

    public bool IsCondtionMet()
    {
        return ConditionIsMet;
    }
}

public class Conversation
{
    public ConditionsChecker ConditionsToMeet;
    public ObjectToDestroy ObjToDestroy;

    public void Start()
    {
        ConditionsChecker = new ConditionsChecker();

        var objectDestroyCondition = new Condition();
        ObjToDestroy.OnDestroy += (sender, args) => { objectDestroyCondition.SetCondition(true) }
    }

    private void OnTriggerEnter(Collider other)
    {
        // Check that the object is indeed the player
        if (ConditionsToMeet.AllConditionsMet())
            StartConversation();
    }

    // Method stub
    private void StartConversation();
}

public class ObjectToDestroy
{
    public EventHandler OnDestroy;

    // Some kind of external force does this either by trigger or how you handle the destruction
    public void DestroyObject()
    {
        OnDestroy?.Invoke(this, null);
    }
}

Note that some of the code is not used directly, but just to offer some more flexibility.