0

So I have this very weird problem with this if statement. This code here

    Debug.Log(gameObject.transform.eulerAngles.y);
    if (gameObject.transform.eulerAngles.y == 20 && x >= -2)
    {
        gameObject.transform.Rotate(0, -20, 0);
        coolDown = true;
    }

does not work. It says the euler angle of y is 20, but for some reason, the if statement is not being checked as true. I tried taking out the euler angle in that if statement and it was checked as true, meaning that the euler angle for some reason is not 20, even though it is printing out as 20. And another weird thing is that this code here

    if (gameObject.transform.eulerAngles.y == 340 && x <= -11)
    {
        gameObject.transform.Rotate(0, 20, 0);
        coolDown = true;

    }

works. It is the exact same code and I don't know why the first code worked and this second one did not. What is wrong with the code?

(x is a variable for gameObject.transform.position.x btw)

here is the whole code (kinda messy cuz I'm not that good at coding yet ;-;)

public float horizontalInput;
public int horizontalInput2;
public float Speed;
public float TimeSpeed;
public bool TimeSpeed2;
public float TimeSpeed3;
public float x;
public int yValue = 20;
public bool coolDown = true;
// Start is called before the first frame update
void Start()
{

}
// Update is called once per frame
void Update()
{

    if (gameObject.transform.position.x <= -11)
    {

    }
    TimeSpeed3++;
    if (TimeSpeed3 == 75)
    {
        TimeSpeed2 = true;
        TimeSpeed3 = 0;
    }
    if (TimeSpeed == 100)
    {
        TimeSpeed2 = true;
    }
    if (TimeSpeed == 30)
    {

        Speed++;
        TimeSpeed = 0;
        if (Speed > 60)
        {
            float v = Speed - 0.8f;
            Speed = v;
            if (Speed > 100)
            {
                v = Speed - 0.18f;
                Speed = v;
            }
            if (Speed >= 105)
            {
                v = Speed - 0.2f;
                Speed = v;
            }
        }
    }
    

    x = gameObject.transform.position.x;
    TimeSpeed++;
    horizontalInput = Input.GetAxis("Horizontal");

    transform.Translate(Vector3.forward * Time.deltaTime * Speed);
    if (Input.GetKeyDown(KeyCode.LeftArrow) && coolDown == true)
    {
        if (horizontalInput < 0)
        {
            horizontalInput2 = -1;
        }
        transform.Rotate(Vector3.up * 20 * horizontalInput2);
        if (x <= -11)
        {
            transform.Rotate(0, 0, 0);
        }
        Debug.Log(coolDown);
        coolDown = false;
    }
    if (gameObject.transform.eulerAngles.y == 340 && x <= -11)
    {
        gameObject.transform.Rotate(0, 20, 0);
        coolDown = true;

    }
    else if (Input.GetKeyDown(KeyCode.RightArrow) && coolDown == true)
    {
        if (horizontalInput > 0)
        {
            horizontalInput2 = 1;
        }
        transform.Rotate(Vector3.up * 20 * horizontalInput2);
        coolDown = false;
    }
    Debug.Log(gameObject.transform.eulerAngles.y);
    if (gameObject.transform.eulerAngles.y == 20 && x >= -2)
    {
        gameObject.transform.Rotate(0, -20, 0);
    }
}

}

Idk v.2
  • 9
  • 3

0 Answers0