Hi all-
I have this fun little test built up: (here)
(float around with WSAD and mouse look, use the blue sockets and hit “1” to add “base blocks” or “2” to add "float blocks, you’ll see!)
Now, I need to have the blocks attach to multiple, obviously- you’ll see this if you try to create a “floor”/etc of any kind. How though, can I do this via script? Obviously I’ll need multiple fixed joints, that’s fine, but not sure how to access each fixed joint individually…
Thanks, hope you enjoy the little demo 
1 Like
Look at the manual page for Component: Unity - Scripting API: Component
Ignore the Variables like hinge-joint, fixed-joint ect, they’re just “quick and easy” accessors to the first component of a set type that has been added. Most times you only use one component of a single type and often you can’t use more than one (like rigidbody). But like I said, they’re just helpful pointers for “common case” scenarios. Instead, look at the functions.
Remember, GameObject is also a type of Component, so from it you can access any other components attached to it.
To get a list of all attached components of type “xyz” you’d use this:
The manual even uses hingejoints for it’s example code.
Yep, I am familiar with accessing components, thanks for the thought though! I actually just figured it out (after leaving it alone to work on something else, the answer just popped up, lol)-
When I add the hinge/fixed/etc joint, I assign it to a variable at the same time- ie, “newJoint = gameObject.AddComponent(FixedJoint)”, and then I can access that specific joint later on- since I’ll have up to 6 joints per cube (one for each face). Or at least, this should work in theory…trying it now! 
Yes, that will work, but so will:
var hingeJoints : HingeJoint[ ];
hingeJoints = GetComponents (HingeJoint);
Then use:
hingeJoints[0]
hingeJoints[1]
hingeJoints[2]
hingeJoints[3]
hingeJoints[4]
hingeJoints[5]
Uhg! My bad, I didn’t see the “…s” in your post, in "GetComponents. That will come in handy down the line, no doubt, thank you much! 