I just realize that Unity doesn’t allow us to assign Rigidbody(gameObject A) into the connectedBody, which is in FixedJoint Component(gameObject B) by scripting!
I went throught the scripting reference and when I clicked connectedBody it shows that it is belonged to HingeJoint(???!)
Do I have another option to assign the rigidbody into the FixedJoint component when the gameplay is on???
No connectedBody belongs to Joint the base class of all joints. That’s why every joint have this property. You have to assign the rigidbody to the variable, not the gameobject. If you ask a question that involves a script that you wrote that doesn’t work, it’s common practise to include the relevant parts of your script.
//C#
public GameObject A;
public GameObject B;
void Start()
{
B.GetComponent<FixedJoint>().connectedBody = A.rigidbody;
}
//JS
var A : GameObject;
var B : GameObject;
function Start()
{
B.GetComponent.<FixedJoint>().connectedBody = A.rigidbody;
}
I guess you’re confused because Unity picks the right component automatically when you drag-drop a gameobject onto the variable. You don’t assign the GameObject to the variable, just the rigidbody.
The above code is not optimal Normally you would use the types you need, but i guess you have gameobject references so i wanted to show the important part.
If that would be a real script you would do it that way:
//JS
var A : Rigidbody;
var B : FixedJoint;
function Start()
{
B.connectedBody = A;
}