Something is making my sprite flip back when i scale flip it on the x axis to show it going the opposite way. But i cant figure out what it is! This is the code
protected void CheckForSpriteFlip ()
{
var flip = false;
//check if sprite needs to flip
if (movement > 0 && !IsFacingRight)
flip = true;
if (movement < 0 && IsFacingRight)
flip = true;
if (flip) {
print(transform.localScaleToString());
Vector3 flipScale = transform.localScale;
flipScale.x *= -1;
transform.localScale = flipScale;
IsFacingRight = !IsFacingRight;
print(transform.localScaleToString());
}
}
When i set print(“”) before and after it shows that the xscale is 1 before the flip and -1 after the flip. But no change shows. And the next time the flip is executed it says the same thing. scale 1 before the flip and then -1 after the flip. So something is flipping it back as soon as it has been flipped to -1. I can also se in the editor that the scale is in fact never -1.
What could do this? I have certainly not coded it.
EDIT:
I now tried with this in the Awake()
protected override void Awake ()
{
base.Awake ();
PlattformGameManager.Martha = this;
MaxSpeed = 4.0f;
transform.localScale = new Vector3 (2, 2, 2);
print (transform.gameObject.name);
}
But still when the object appears its scale is 1.
EDIT2:
When running the game, i pause, rescale the object with the editor. It works. Moment i run the game the scale is reset to 1, 1, 1. What is this sorcery?!