Hi, so I’m trying to get the my enemy and player sprites to flip whenever they face the other direction. Right now, I have it just use the negative of whatever the player or enemies change direction. The only thing is, it isn’t working and it is crashing unity anytime I play. I you could help me out, I’d greatly appreciate it!
public bool FacingRight = true;
public float Righty = 1f;
public float Lefty = 1f;
void Update ()
{
if (transform.rotation.eulerAngles.z > 90 && transform.rotation.eulerAngles.z < 270 && FacingRight == true) {
FacingRight = false;
transform.localScale += new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
if (transform.rotation.eulerAngles.z < 90 || transform.rotation.eulerAngles.z > 270 && FacingRight == false) {
FacingRight = true;
transform.localScale += new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
}