[SOLVED]scroll down for answer. I'm creating a car game that controls with xbox one controller. this is steering wheel controller. my code is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class steeringrotation : MonoBehaviour {
void Update () {
if (transform.rotation.eulerAngles.z == -90) {
Debug.Log("g");
//transform.Rotate(0,0,transform.rotation.z+25);
}
}
}
i changed the steering wheel z rotation to -90 and writed code: transform.rotation.eulerAngles.z == -90
and it doesn't Debug.Log("g");. what do i do? I maked -90 to 630. but again.
I Asked Google's assistant bard i copy&pasted the code and the codes doesn't work! answer: In the code i debug.log the rotation. when it was -90, debug.log says that WAS 270!!!!!!!!!. this is completed code:
if (transform.localRotation.eulerAngles.z >= 270)
{
Debug.Log("g");
}
i found the transform.localRotation.eulerAngles.z in the unity discussions. first answer https://discussions.unity.com/t/how-to-get-rotation-of-an-object-using-c/166443
Did you set z rotation on the transform from the inspector? And does the steering wheel object have a parent transform? If so, try to use
transform.localEulerAngles.zinstead as this is the value that actually corresponds to what you see in the inspector.