Covert to C# from java script

my project about racing car. i use C#, and when i begin at wheel collider steps. i find that code: function SetFriction(MyForwardFriction :float,MySidewaysFriction:float){

frWheelCollider.forwardFriction.stiffness = MyForwardFriction;
flWheelCollider.forwardFriction.stiffness = MyForwardFriction;
rrWheelCollider.forwardFriction.stiffness = MyForwardFriction;
rlWheelCollider.forwardFriction.stiffness = MyForwardFriction;

frWheelCollider.sidewaysFriction.stiffness = MySidewaysFriction;
flWheelCollider.sidewaysFriction.stiffness = MySidewaysFriction;
rrWheelCollider.sidewaysFriction.stiffness = MySidewaysFriction;
rlWheelCollider.sidewaysFriction.stiffness = MySidewaysFriction;


it run at java script but i can’t convert to C#. Please help me!

The answer is simple. forwardFriction is of type WheelFrictionCurve which is a struct. Since frWheelCollider is a property, when you write:


You actually read the forwardFriction struct. Whenever you read a struct-property you get a copy of it. So you change the stiffness value of that copy but you don’t assign the copy of WheelFrictionCurve back to forwardFriction. It’s the same with transform.position which is also a struct property.

Just do it like this:

var curve = frWheelCollider.forwardFriction;  // get a copy
curve.stiffness = MyForwardFriction;          // change the value
frWheelCollider.forwardFriction = curve;      // assign the copy back

This is the only way to change a member of such a property struct. In Unityscript (JS) the compiler generates this code behind the scenes.

The simple answer is that you only need to change the line

 function SetFriction(MyForwardFriction :float,MySidewaysFriction:float){


 void SetFriction(float MyForwardFriction, float MySidewaysFriction){

but I suspect there is more to your problem than you have included in your question.