I want to flip 2d sprite without using code to change its scale because it has a problem with child object that attach to it, Rotate 180 degree work but in scripting. It won’t work. I don’t know which component use t rotate object at all as I never use rotate code at all. Here my code:
if(deltaX > 0){
//transform.localScale = new Vector3 (1, 1, 1);
}else if(deltaX < 0){
//transform.localScale = new Vector3 (-1, 1, 1);
//transform.localEulerAngles = new Vector3 (0f, 180f, 0f);
transform.Rotate(0,180,0);
}
I’ve tried that. It didn’t work. There’s nothing work beside the localScale or Flip Sprite from the Sprite render component, but it has problem with my child property that has different setup.
What is the actual rotate code for Unity? There’s so many rotate code but non of them work for me.
I’m working on 2D project. I didn’t want the object to rotate overtime but instant rotate. The transform.Rotate and other roate code doesn’t work. What is wrong with these code?
All we know is small peace of the code. So it’s hard for us to tell you what’s wrong.
So please add the debug.Log(); or print(); to help you trouble shoot. please verify that the code is being executed.
The deltaX is from the Input.GetAxis (“Horizontal”) which mean deltaX > 0 facing right and deltaX < 0 facing left.
I’ve debug it. It’s work fine with localScale but it won’t work with any rotate code from transform component.
It was a debug code I forgot to remove. I was so frustrated and thinking that there is a proper rotation code.
Thank for helping me out. I think that I’ve inspect everything. I still make the same mistake again & again as a programmer. Always think outside of the box!