How do i change the upper angle limit and lower angle limits of a hingejoint2d object?
I get the error: Assets/AngleChanger.cs(35,36): error CS1612: Cannot modify a value type return value of `UnityEngine.HingeJoint2D.limits'. Consider storing the value in a temporary variable
I am trying to change the limits via script.. heres my code:
public int num;
public HingeJoint2D angleLimit;
void Start ()
{
num = 90;
}
public void addNum2()
{
float num2;
if (num > 90 || num == 90)
{
Debug.Log ("You can't go higher than 90 degrees!");
}
else
{
num += 5;
num2 = (90 - num) * -1;
angleLimit.limits.max = num2;
}
}
public void subtractNum2()
{
float num2;
if (num < 0 || num == 0)
{
Debug.Log ("You can't go lower than 0 degrees!");
}
else
{
num -= 5;
num2 = (90 - num) * -1;
angleLimit.limits.max = num2;
}
}
}
Im trying to change the upper and lower limits for my hingejoint2d but it wont let me change it. is this the correct code for it? if not, whats the correct call and what am i doing wrong
Answer by Floshosho · Dec 01, 2015 at 07:18 PM
I found out what i was doing wrong, problem solved :)
Your answer
Follow this Question
Related Questions
Joint two carriages with hingejoint in runtime 0 Answers
Children of a hingejoint not colliding with parent's mesh when connectedBody is assigned 1 Answer
Rope (made with joints) connected to a movable transform acts weirdly 0 Answers
How do I model a piston? 0 Answers
how to test if something enters a specific trigger and set that object to a gameobject variable!?!? 1 Answer