Search Unity

Could someone please tell me why the code bellow is invoking error CS1612. A float case this time!

Discussion in 'Scripting' started by vagalume, Dec 3, 2014.

  1. vagalume

    vagalume

    Joined:
    Sep 26, 2014
    Posts:
    3
    Hi fellows, Could someone please tell me why the code bellow is invoking error CS1612 - "Cannot modify a Value Type of 'CharacterJoint.lowTwistLimit.limit'. Consider storing the value in a temporary variable"?

    This line is within Couroutine, if it matters.

    float temp =-90f;
    gameObject.GetComponent<CharacterJoint>().lowTwistLimit.limit = temp;


    I´ve seen a lot of answers about position problems invoking the same error but they were all solved spreading Vector3 and remounting it in a new Vector3 within a temporary variable. I tried to apply the same concept to my problem, unsuccessfully.

    If you could give me a hint, it would be great! Besides.. I'm very new to Unity and very grateful for all the knowledgement you guys are sharing. As soon as I feel reliable to help you guys, assure I will!
     
  2. GetUpKidAK

    GetUpKidAK

    Joined:
    Apr 9, 2013
    Posts:
    84
    Have you tried assigning the lowTwistLimit variable to a temporary SoftJointLimit variable?
     
    vagalume likes this.
  3. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    382
    Code (csharp):
    1.  
    2. CharacterJoint cj = gameObject.GetComponent<CharacterJoint>();
    3. SoftJointLimit sjl = cj.lowTwistLimit;
    4. sjl.limit = 90f;
    5. cj.lowTwistLimit = sjl;
    6.  
     
    vagalume likes this.
  4. vagalume

    vagalume

    Joined:
    Sep 26, 2014
    Posts:
    3
    Hi Guys!
    Very enlightening for me! It works!
    Thanks a lot!