Search code examples
c#unity-game-enginerotationquaternions

Issues with Quaternion and eulerAngles within if-statement in Unity


I have been looking for an answer and testing different things so but it isn't working so I'm asking about it here. The error I'm getting is

"Cannot modify the return value of 'Quaternion.eulerAngles' because it is not a variable"

And here is the code:

void FixedUpdate ()

{
    Quaternion rot = transform.rotation;
    if (rot.eulerAngles.y =< 91)))
    {
        rb.AddTorque(transform.up * rotationStopper);
    }
}

Solution

  • if (rot.eulerAngles.y =< 91)))
    

    should be

    if (rot.eulerAngles.y <= 91)))
    

    The top one is trying to assign to the y variable and fails because it doesn't understand what "< 91" is.