- Home /
Possible to return the names of gameobjects inside a rect?
As I said in the title, is it possible to create a rect and check which objects is inside it and return their names?
I tried using rect.Contains but couldn't get it to return the names, the only thing I was able to do was check IF an object is inside but not getting the name.
The reason I want to do this is because I want to make a selection box thing and then add the gameobjects inside the box to a list of selected units. Any help is appreciated :)
If you can already check if an object is inside the rectangle, then you almost there. the psuedo code would look something like this.
if object is in rect {
if objects name is <insert> {
<do something>
}
}
The way to get a name is using the GameObjects property of .name
Sorry for the delayed answered, I think I'm going to rethink and try something different. Since rect seems to only use 2d positions making it hard for me to check if an object with a 3d position is inside.
I said before that I was able to check IF an object was inside, but that doesn't seem to be the case. However if you know how I'd go about checking 3d positions inside a 2d rect, feel free to help me. Otherwise I'm just going to try do insatiate a cube with a collider or something.
Thanks for the answers so far though
That's how I would likely do it. It's simple and Unity handles everything for you in that case.
Answer by grmlfimmel · Jan 09, 2017 at 05:07 PM
Could be that I get the question wrong but what about a Trigger/Collider on the rect and checking the Method OnTriggerStay(collider col) for the objects within the collider?
Your answer
Follow this Question
Related Questions
Rect.Contains Screen Resolution Problem 3 Answers
Switching between multiple classes 2 Answers
Realtime object loading to scene 1 Answer
Rect.Contains not working 1 Answer
GUI label dimensions bug 2 Answers