How would you check if a specific collier is not present?

If player1 is not present on an objective, then the objective is not “defended”. I tried onTriggerExit - it works if the player leaves the objective - but not if it is destroyed.
I tried onTriggerStay and wrote the following but it gave me false when other colliders like player2 were present. How can this be solved?

  if (col.gameObject.tag = "player1")
    defended = true
    else
    defended = false

So it depends on what you’re looking to do but I’m assuming that it works like this:
_
It only takes 1 player to be inside the trigger for it to be marked as “defended”. Other players coming in/out should not impact this. ie:

  • Player 1 enters trigger. Objective is “defended”

  • Player 2 enters trigger. Objective is still “defended”

  • Player 2 leaves trigger. Objective is still “defended”.
    _
    This might not be the best way to do it but I’m writing it from memory so not tested it. Basically you want three things to happen. When a player enters the trigger the objective is marked as defended. Should a player leave the trigger will mark the objective as “undefended”. This is to account for the “last” player leaving the trigger area. To get this to work you need to check if someone is still inside the trigger and set it back to true.
    _

  • Player 1 enters trigger (Objective Defended)

  • Player 2 enters trigger (Objective Defended)

  • Player 2 leaves trigger (Objective Undefended) this will only be for a single frame.

  • Player 1 is still inside trigger. (Objective Defended)
    _
    You also need to set the player’s tag to “Player” or whatever else you choose to call it. The script containing the code below should be attached to the gameobject that has the trigger.

    void OnTriggerEnter(Collider other)
    {
    if (other.tag == “Player”)
    {
    Debug.Log(“Objective Defended”);
    }
    }

    void OnTriggerExit(Collider other)
    {
    if (other.tag == “Player”)
    {
    Debug.Log(“Objective Undefended”);
    }
    }

    void OnTriggerStay(Collider other)
    {
    if (other.tag == “Player”)
    {
    Debug.Log(“Objective Defended”);
    }
    }