- Home /
How to name a physics joint, and refer to it?
I have two HingeJoint components on a Game Object. But I can't find a way to name them? They just show up as 'Hinge Joint.'
This is confusing to work with, and what's more, I would like to refer to them in my C# Scripts.
If I do GetComponent<HingeJoint>() in my script, how can I control which joint will be returned? I tried passing an index value to GetComponent() but it is not accepted. 
Answer by xxmariofer · Jan 15, 2019 at 09:22 PM
Unity recomends not to use more than 1 hingejoint since makes work harder,but u can get both joints using GetComponents in plural example:
public class GetComponentsExample : MonoBehaviour { // Disable the spring on all HingeJoints in this game object
 void Start()
 {
     Component[] hingeJoints;
     hingeJoints = GetComponents(typeof(HingeJoint));
     foreach (HingeJoint joint in hingeJoints)
         j//stuff
 }
}
for knowsing which hinge was the first or the second one you can access a property called connectedBody or something like that and compare the name of that rigidbody.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                