I was trying to make a script for when my game object (It’s a car) is not standing up it disables the movement script. This was working when the game object is on it’s sides but not when it is upside down. The script is still enabled when it is upside down. Here is my code for detection the rotation on the X axis and disabling the script. The name of my movement script is PlayerMovement.
I tried a lot of fixes but non of them ever worked. -Thanks
public GameObject Car;
public PlayerMovement PlayerMovement;
// Start is called before the first frame update
void Start()
{
Car.SetActive(true);
PlayerMovement.enabled = true;
}
// Update is called once per frame
void Update()
{
float xRotation = transform.eulerAngles.x;
// Check if the object is upright or upside down
if (xRotation >= -10 && xRotation <= 10) // Narrowed range for upright
{
Car.SetActive(true);
PlayerMovement.enabled = true;
}
else
{
Car.SetActive(true);
PlayerMovement.enabled = false;
}
}