- Home /
Images Rotation
Hi guys..
i just wanted to rotate may images in my game.. this is the script
public float rotationSpeed = 1.0f; private Vector3 rotateSpeed;
void Start(){
}
void Update ()
{
if (Input.GetMouseButton (0))
{
rotateSpeed = new Vector3 (-Input.GetAxis ("Mouse X"), 0);
}
transform.Rotate (0.0f, rotateSpeed* rotationSpeed * Time.deltaTime, 0.0f);
}
my problem is when i started to click my mouse and drag it the rotation of my image didnt stop..
i just wanted to minus the speed of image when its rotating. can you give some example using my codes?
Second Question.
when the image is focus on the screen or trigger to the collider. the rotation will stop.
Answer by chronicfail · Aug 02, 2013 at 07:06 AM
It doesn't set rotate speed to zero when you stop using the mouse, so it carries on at whatever what was the last Input.GetAxis(MouseX) before the mouse button was released.
Also, the Vector3 in that script has nothing to do with rotation- you need to use the rotationSpeed variable, as rotateSpeed has no effect on rotation in this script.
}
void Update ()
{
if (Input.GetMouseButton (0))
{
rotationSpeed = -Input.GetAxis ("Mouse X");
else{
rotationSpeed=0.0;
}
}
transform.Rotate (0.0f, rotationSpeed * Time.deltaTime, 0.0f);
}
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
How to always rotate clockwise 1 Answer
Making a rotating object rotate with a parent object 1 Answer
How to rotate about 360 on a coroutine 3 Answers
How to rotate a tank turret and gun? 2 Answers