-1

I get the following error every time I run the code:

error CS0120: An object reference is required to access non-static member `UnityEngine.Joint.breakForce'

Joint.breakForce = Mathf.Infinity;

How can I properly write this? The break force can be set to Mathf.Infinity to render the joint unbreakable.

1 Answers1

1

Whenever you see the error:

An object reference is required to access non-static member [...]

This would strongly suggest that you are using a class name where you should actually be using a class instance. In this case, it's saying that you need an instance of Joint (or rather, FixedJoint, right?) in order to change its breakForce value.

To fix this, you will first need to use GetComponent() to retrieve the instance of FixedJoint from the current GameObject, and only then set its breakForce. For example, if you do this in your Start() method:

Start() {
    GetComponent<FixedJoint>().breakForce = Mathf.Infinity;
}

Hope this helps! Let me know if you have any questions.

Serlite
  • 12,130
  • 5
  • 38
  • 49