I’m working on a small project in 2D, and made walk cycles for every direction but left, figuring I could just flip the sprite in code. So I made a bit of code to tell it to flip when moving -x, and it worked (judging by the inspector), but it also prevents everything from rendering, leaving only the background color. Here is the code that is causing the problem:
if (Input.GetAxisRaw("Horizontal") < -0.5f)
{
transform.localScale = new Vector2(-0.5f, 0.5f);
}
else
{
transform.localScale = new Vector2(0.5f, 0.5f);
}
Add a bool variable isFacingLeft;
Change that block of code you provided to this:
float movementDirection = Input.GetAxisRaw("Horizontal");
if(movementDirection > 0 && isFacingLeft == true)
{
Flip()
}
else if(movementDirection < 0 && isFacingLeft != true)
{
Flip();
}
And then add this block of code to that script you have there:
private void Flip()
{
isFacingLeft = !isFacingLeft;
transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y);
}
That flips the moment you change directions; if you want you can change the if statements that look like this:
if(movementDirection > 0 && isFacingLeft == true)
To this (like you have in your code):
if(movementDirection > .5f && isFacingLeft == true)
That should flip character on movement changes, let me know if you have issues; I don’t have Unity with me and wrote this answer on this forum, so there might be errors.
@I_Am_Err00r Thank you for the help - It now renders everything correctly on startup, but if you turn left, everything vanishes.