- Home /
Question by
saturn118 · Aug 22, 2013 at 10:47 AM ·
c#javascriptvariableassign
Assigning a unity component variable issue
I'm using Unity 3 and I'm trying to perform a simple assignment of the variable linearLimit>limit within the ConfigurableJoint component. I'm using the code below but I keep getting the error "Cannot modify a return value, try placing it within a variable first". Am I doing something wrong?
//My Code
ConfigurableJoint cj = gameObject.GetComponent(); cj.connectedBody = objectToGrab;
cj.xMotion = ConfigurableJointMotion.Limited;
cj.yMotion = ConfigurableJointMotion.Limited;
cj.zMotion = ConfigurableJointMotion.Limited;
float newLimit = 1.0f;
cj.linearLimit.limit = newLimit;
//Unity's public Accessor/Mutator for that variable
public float limit { get {return this.m_Limit; } set {this.m_Limit = value; } }
Comment
Best Answer
Answer by InfiniBuzz · Aug 22, 2013 at 10:50 AM
Hi
to set a configurable joint limit you have to:
ConfigurableJoint cj = gameObject.GetComponent();
cj.connectedBody = objectToGrab;
cj.xMotion = ConfigurableJointMotion.Limited;
cj.yMotion = ConfigurableJointMotion.Limited;
cj.zMotion = ConfigurableJointMotion.Limited;
// setup a SoftJointLimit instance to modify...
SoftJointLimit newLimit = new SoftJointLimit();
newLimit.limit = 1.0f;
newLimit.*otherVars* = cj.linearLimit.*otherVars*; // if needed
// ... and set the joints limit to the SoftJointLimit instance
cj.linearLimit = newLimit;
hope it helps ;)
Thanks. It doesn't mention that anywhere on the documentation for that page