- Home /
Question by
imLor · Dec 27, 2021 at 08:53 PM ·
2d game2d-physics
How to find a Rigidbody component on a specific object by object name or tag!?
Is it Possible? You can do this as for the transforms but for the rigidbody:
void Start ()
{
GameObject.Find("Name Object").transform;
}
Comment
Answer by Casiell · Dec 28, 2021 at 06:18 PM
For Rigidbody (or any other component) you use GetComponent()
So in your case it would be GameObject.Find("Name Object").GetComponent()
Just a note here is that searching game objects by name or tag is strongly discouraged, simply because it's extremely slow, especially with bigger scenes.
Hello. Thanks for the answer! And what would you advise instead of searching for objects by name or tag?