- Home /
The question is answered, right answer was accepted
How do you get a component of a GameObject if you know only its position?
I'm making trusses and I have to share vertices in order to connect them (The vertices are GameObjects). The vertices are all named the same so I cannot find them by name. If there is a vertex (GameObject) at the position I set to create a new vertex in my script, can I get the Transform component of that GameObject only knowing its position?
Answer by vir1234 · Jun 29, 2017 at 03:45 PM
Try This
foreach (GameObject go in GameObject.FindGameObjectsWithTag("yourGameObjectTag"))
{
if (go.transform.position == yourobjectposition )
{
go.getcomponent<whatever>();
}
}
Thank you very much. I am still relatively new to program$$anonymous$$g so I never used foreach before, but I think it will be very beneficial to my project and future ones as well!
Answer by Major · Jun 29, 2017 at 01:59 PM
There is no built in method for this. However, I believe it would be much easier to reverse the flow of information. Instead of having your controller get information from the vertices, have the vertices send their position to the controller.
Follow this Question
Related Questions
Copy Transform 1 Answer
Can't get enemy to chase player 2 Answers
Removing Vector3 Decimal for Position 2 Answers
What is the reasoning of multiplying by Time.deltaTime 1 Answer
does not work check if dead 1 Answer