How can I rotate a sprite in Unity 4.3?
rotation, sprite, unity-game-engine
Solution
I'm not able to try it with Unity right now, but my guess is that it is either rotating just 1º, so you are not able to notice it, or rotating 360º, and so it really stays the same.
Try to break down your problem:
- Instead of `transform.Rotate` try `transform.Translate(20f, 20f, 20f)` just to make sure it is recognizing the input;
- Use a different value instead of `1.0f`, such as `0.1f` and `30.0f` (I think 30.0f would be 30º, but I'm not sure);
- Try changing the rotation on the other axes `y` and `z` instead of `x`;
- Use the alternative definition `Rotate(Vector3 axis, float angle)`.
Hope it helps!
Problem
I would like to rotate a sprite on the scene by pressing the left or right arrows keys (think of the spaceship in Asteroids). I have placed the sprite in question on the scene and created a script, but am not really certain of where to go from there. My current script looks like this: ``` using UnityEngine; using System.Collections; public class RotateLeftRight : MonoBehaviour { public float speed = 1.0f; public string axisName = "Horizontal"; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.LeftArrow)) { // left transform.Rotate(-1.0f, 0.0f, 0.0f); // does nothing, just a bad guess } if(Input.GetKeyDown(KeyCode.RightArrow)) { // right transform.Rotate(1.0f, 0.0f, 0.0f); // does nothing, just a bad guess } } } ``` I just coded the above without any knowledge of what would happen (and, hardly surprising, nothing appears to happen at all). Any advice on how to rotate the sprite and control the speed of the rotation would be greatly appreciated.