- Home /
How to find all gameObjects in a bounding area?
Hello, I need to find all gameobjects in a cube area, i want to do this in an custom inspector though so i cant use any runtime methods.
Thanks in advance.
Update . The preferably the entire bounds of the objects should be checked agaisnt the area (if there is a way to do that) but if that isnt possible then just pivot point.
The cube is aligned to the global axis, not to any object.
Some info you might want to add to your question:
Is it just the pivot point that must be in the cube area, or does the entire object need to be within the cube, or is it any part of the mesh within the specified cube area?
If it is the entire object, is it good enough to check a bounds of the of the objects, or do you need the actual mesh checked against the cube area?
Are the objects axes aligned or are they rotated?
Answer by tw1st3d · Dec 26, 2013 at 08:58 PM
This is pseudo code, I haven't worked with C# in quite a while, but it should make sense as to what it does. Take a look, and if it doesn't work, try and fix it ( cause that's how you learn :)! )
using UnityEngine;
using System.Collections;
using System;
public class InsideOf : MonoBehavior
{
protected List<GameObject> insideMe = new List<GameObject>();
private void OnTriggerEnter(Collider e)
{
if(e typeof GameObject)
{
if(!this.insideMe.contains(e.gameObject))
{
this.insideMe.add(e.gameObject);
}
}
}
private void OnTriggerExit(Collider e)
{
if(e typeof GameObject)
{
if(this.insideMe.contains(e.gameObject))
{
this.insideMe.remove(e.gameObject);
}
}
}
}
hello,
That should work for runtime yeah,
Im looking to make a list of objects in a custom inspector gui. So any methods like ontriggerenter/exit wont work. (unless i am mistaken, which is possible)