Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do I return true when all objects with a tag have left an area?

I'm making a game with the goal of pushing a bunch of objects off of a platform (First time doing a game w/o tutorial).

Game: https://gyazo.com/cafda89025138fb95b0640156562f19c

The objects you push off are prefabs and are all under one tag. I want to rig a system to tell you that you have won the game when all of the objects have been pushed off (and you haven't fallen off yourself) by detecting when objects of the tag are no longer in a trigger which encompasses the platform. I am however new to Unity and only know little C#, how would I go about detecting when there are no objects in the trigger area with the tag, without it detecting the player, then returning a true value? Many thanks beforehand.

Best Answers

  • JIMMY_VASHI04JIMMY_VASHI04 Member
    Accepted Answer

    Make a list on the trigger object

    Then in the ontriggerenter method check for the tag you want if its correct tag then add that gameobject to list.


    In the ontriggerexit method check for the tag and also check that the gameobject is already in the list or not if it is then remove it


    This checkings will make sure that all the objects that are in the trigger are correct tagged and also they are not player.


    Then in the update method you can easily check for all objects are thrown out by check the count of that list.

  • KiwiSpikeKiwiSpike Member
    Accepted Answer

    Thank you very much! I will give this a try soon.

Sign In or Register to comment.