- Home /
Test if x,z is allrdy a GameObject
Hey Guys,
so i am trying to generate a Level. So i wrote a littel script which creates me my Planes for the level (recursive).
Now i want to check if there is allrdy a gameObject been created at a specific position ? How to do this ?
I was thinging about this:
http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html
or a Gameobject holding a list of all GameObject based on theyr coordinates, and just check this list if there is allrdy a Item on this position !? What is more easy to accomplish ?
What is the smarter solution ?
Greetings
Teiwaz
Answer by robertbu · Jun 11, 2013 at 05:56 PM
I doubt you want Physics.SphereCast(). Instead take a look at Physics.CheckSphere() or even Physics.OverlapSphere(). Note all three of these require the planes to have colliders.
What method you choose depends on the number of elements you are creating, when you are creating them (i.e. while playing vs. at Start()), and whether they have colliders. The most efficient method would be to keep your own list and compare the distance. If you tag all the objects as you go, you can generate a list using GameObject.FindObjectsWithTag(). Not as efficient, but probably better than PhysicsCheckSphere().
Answer by Teiwaz · Jun 12, 2013 at 07:58 AM
I now did it with a raycast Vector3.bot. Thats works, but i guese if i just save everything into a Array, it would be much faster.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
make a wedge moveable 0 Answers
collider animation 1 Answer
wheel colliders HORRIBLE PROBLEMS is this really me? 2 Answers