Now let’s take a look on this example of writing a script for rotating a 2D sprite in Unity. This will be done in a simple line of code.
The solution is very simple.
You should access a game object of this sprite and manipulate with its transform object:
transform.Rotate(Vector3.forward * -90);
Random objects rotation
If you want to rotate generated objects (platforms, enemies, etc.) with a random angle, you need this:
transform.Rotate (Vector3.forward * Random.Range(-10, 11));
This line will rotate objects for a random angle with leaning from -10 degrees to 10 degrees. You can play with numbers in Range method to get the rotation that will be perfect for your game.