Quantcast
Channel: Questions in topic: "temporary"
Viewing all articles
Browse latest Browse all 97

converting javascript to c#

$
0
0
Hey, I ran into a problem and I don't know how I can fix this, this task is easy to do in javascript, but for me it's quite harder in c# For an example of my problem I'll give you a part of the script in js: RightSki.rigidbody.AddRelativeTorque(0,- MovementSpeed, 0); LeftSki.rigidbody.AddRelativeTorque(0,- MovementSpeed, 0); LeftHand.hingeJoint.motor.force = MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; LeftLeg.hingeJoint.motor.force = - MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; LeftFoot.hingeJoint.motor.force = MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; LeftHand.hingeJoint.spring.spring = 1; LeftLeg.hingeJoint.spring.spring = 1; LeftFoot.hingeJoint.spring.spring = 1; So this works perfectly, but when I tried making it in c#: //Hand leftHandObject.hingeJoint.motor.force = MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; leftHandObject.hingeJoint.spring.spring = 1f; //Leg leftLegObject.hingeJoint.motor.force = -MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; leftLegObject.hingeJoint.spring.spring = 1f; //Feet leftFootObject.hingeJoint.motor.force = MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; leftFootObject.hingeJoint.spring.spring = 1f; //Skis leftSkiObject.rigidbody.AddRelativeTorque(0f,-MovementSpeed, 0f); rightSkiObject.rigidbody.AddRelativeTorque(0f,-MovementSpeed, 0f); when I did this in c# I get this error in most of the lines: error CS1612: Cannot modify a value type return value of `UnityEngine.HingeJoint.motor'. Consider storing the value in a temporary variable So I tried making a temporary value that was like this: `float motorForce1 = MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;` and replaced: leftHandObject.hingeJoint.motor.force = MovementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; with: leftHandObject.hingeJoint.motor.force = motorForce1; but I still get the same problem, so how do I get this to work? thanks in advance

Viewing all articles
Browse latest Browse all 97

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>