- Home /
Hinge joint spring variable (c#)
Hi, for my game I need to change the spring of some hinge joints and also the motors.
But I get this errors: Cannot modify a value type return value of UnityEngine.HingeJoint.motor'. Consider storing the value in a temporary variable. Cannot modify a value type return value of
UnityEngine.HingeJoint.spring'. Consider storing the value in a temporary variable
What's even worse is that unity documentation doesn't help at all, since it has the same mistake in there: http://docs.unity3d.com/Documentation/ScriptReference/HingeJoint-spring.html
So, how can I save the spring of an hinge joint inside a variable? Thanks in advance
Answer by perchik · Mar 03, 2014 at 05:56 PM
First, let me say that I don't know anything about JointSprings and/or how to use them.
However, I am familiar with making things work in Unity.... so perhaps:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
JointSpring mySpring;
void Start() {
mySpring = hingeJoint.spring;
mySpring.spring = 10;
mySpring.damper = 3;
mySpring.targetPosition = 70;
hingeJoint.spring = mySpring;
}
}
yeah, by the time I already made it :) I'm having some other issues now so I don't know if it's working correctly though, also, I don't know if I'll really have to do that line: hingeJoint.spring = mySpring since the spring will be assigned from the inspector it'll probably change it directly, I don't know tho.
Yeah, it will work, anyway I'll use javascript for this project, or atleast this script, it's so much more complicated to make this script in c#.