• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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 ;)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image saturn118 · Aug 22, 2013 at 11:00 AM 0
Share

Thanks. It doesn't mention that anywhere on the documentation for that page

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I assign the main camera to a variable? 2 Answers

Cannot implicitly convert type `void' to `float' 1 Answer

How to go about modifying a variable in a C# script from within a UnityScript (Javascript) that resides in a different Gameobject? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges