How can I make an object rotate to one point and not keep looping?
I have an object with this function:
if(Input.GetKey(KeyCode.Mouse0)){
transform.Rotate (0,0,900*Time.deltaTime);
}
My object just keeps rotating forever , when my objective is to , when the user touches/mouse the object rotates and changes the side its pointing by 180 degrees , and then back to 0. How can I make it stop rotating?
Answer by brazmogu · Nov 11, 2015 at 06:18 PM
I'm not sure how you expect that to happen, considering what you are doing is rotating the object at 900 degrees per second while the mouse/touch is down.
My best suggestion is to make a coroutine to do the rotating, activate it on GetKeyDown(only when it's pressed, not while it's being pressed) and use a flag to avoid activating it while it's still running.
Your answer
Follow this Question
Related Questions
Any simple ways of keeping track of simple rotation? 2 Answers
Rotate clockwise/counterclockwise using Quaternion.Slerp() 0 Answers
Quaternion.Euler doesn't work right? 2 Answers
What's wrong with this Quaternion rotation? 1 Answer
Rotational Velocity, Quaternions, Vector3 & Transfrom.rotation - Help 1 Answer