- Home /
Finding a game object for its transform?
Is there any way to locate a GameObject given its transform, name and/or parent?
I'm trying to delete a series of tiles on a grid full of identically-named tiles upon game over, but I can't seem to find the objects, even though I know their positions. Maybe instead there's a way to delete whatever object lies at a certain position? Keep in mind the tiles that have to be deleted (and therefore, which positions to delete) aren't static; they change every time I run the game.
The problem with finding a GO based on it's Vector3 position is that these are floating numbers so there's potentially a lot of accuracy that makes differentiating between a position to search for and any given GO position unreliable.
If you use a grid anyway, you could declare a two or three dimensional GameObject array to quickly find the GO at any given x,x,x coordinate.
On a side, note, having seperate GOs for every tile isn't recommended for anything but the smallest of maps because the resulting high number of GOs will kill performancy very quickly (a small grid of 10x10 is already 100 GOs).
Thank you! I found a way around it by using Colliders to delete objects. I was lucky that that was an option; its not a general solution.
Answer by Pzula · Jul 24, 2016 at 03:41 AM
You could perhaps use a loop to go through each grid position and cast a ray to see if an object lies there. Or maybe you could make a GameOver event, have these tiles listen to the event, and then delete themselves when the event is fired.
Your answer
Follow this Question
Related Questions
Why do we access children through an object's transform? 2 Answers
How to check parent value instead name value(more details in post) 3 Answers
How can I access the children of a Transform? 5 Answers
Child Transform 1 Answer
Make a GameObject child to a "Dragged Reference" GameObject doesn't work! 0 Answers