- Home /
check if there are no object inside a trigger
I've got Quad attached to the camera and is above it, with a mesh Collider attached to it, I'm making a vertical platformer, and would like prefabs to be instantiated when there are no objects inside that trigger. how can i check if there are no objects in a trigger?
Answer by DoTA_KAMIKADzE · Apr 02, 2015 at 02:18 PM
Your objects should contain triggers as well to cooperate with other trigger, and if they do just use this:
P.S. And just for the sake of completeness - alternatively you can always maintain sort of a "contained triggers" list yourself using this 2 functions:
this is good only if theres 1 object, ive got lots of object entering and exiting, i need when its completely empty or exits the highest platform. is there a way maybe to check for the platform with the highest y?
Nope this is fine for any amount of objects. You just need to use those functions inside your "Area trigger object's script" and every other object should have trigger, that's it. Here is the example how to use them:
Click here to see how to use those functions.
P.S. There are examples for both cases, choose approach that you like more.
Answer by kingcoyote · Apr 02, 2015 at 05:26 PM
There are a few static functions in the Physics class that might solve this problem, depending on the shape of the area you are searching, the size of the area, and the size of the objects you are looking for.
OverlapSphere will return an array of all colliders that are in, or touching, the sphere. This one would work best if a sphere is suitable for the sizing.
CheckSphere is similar, but returns a bool indicating the presence of a collider and may not check inside the sphere.
RayCast casts a ray and returns information on what it hits. But you would need an array of rays cast, and this could be computationally expensive, depending how large of an area you are looking at and how small the objects you are looking for will be.
SphereCast casts a sphere along a ray, which is essentially a capsule version of SphereCheck.
Your answer
Follow this Question
Related Questions
Disable Camera Movement,Stop camera movement 0 Answers
Emit Particle upon Death 2 Answers
Camera switching : C# onTriggerEnter not working 1 Answer
How do I move the camera to another object in the scene on mouse down? 1 Answer
How can I set up cameras to track the player from room to room? 1 Answer