Search Unity

C# Access property question...

Discussion in 'Scripting' started by littlelingo, May 23, 2008.

  1. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Hiya,

    I am reworking some of my code from JS to C# ( mostly because I want to ) and came across something like this:

    Code (csharp):
    1.  
    2.  hingeJoint.spring.targetPosition = 60;
    3.  
    After some deliberation and trying a couple different things, I just can't seem to figure out how to write that. Could someone provide me some insight?

    TIA,

    -- Clint
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    You need to do it like this:

    Code (csharp):
    1. JointSpring spring = hingeJoint.spring;
    2. spring.targetPosition = 60.0f;
    3. // If you want to alter any other members of spring, do it here
    4. hingeJoint.spring = spring;
     
  3. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Thank you!

    -- Clint