Return transform to normal rotation after rotation key pressed?
I am trying to rotate the transform only when the mouse button is held, and when it's released, the object returns to it's normal rotation
if (Input.GetMouseButton(0))
{
Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(pos), Vector2.zero);
Debug.Log(pos); // space indication
// we have something under our pointer
if (hitInfo)
{
if (hitInfo.transform.gameObject.tag == "left")
{
playerMovement += new Vector2(distance, distance1);
transform.Rotation(0, 0, 12 * Time.deltaTime);
}
if (hitInfo.transform.gameObject.tag == "right")
{
playerMovement += new Vector2(hey1, hey2);
transform.Rotate(0, 0, -12 * Time.deltaTime);
// or do something else
// (...)
}
}
And then after this I do
if (Input.GetMouseButtonUp(0))
{
transform.Rotate(0, 0, 0);
}
However the rotation stays the same after the mouse button is released. Any ideas? Thanks
Comment
Your answer
Follow this Question
Related Questions
Spawn added objects into a circle 1 Answer
how to do on single click fire and on drag appears the joystick and get the input from joystick 0 Answers
Movement Unit (RTS) 0 Answers
Car from Unity's standard assets giving me of null reference errors 0 Answers
How do I resolve, get_isActiveAndEnabled can only be called from the main thread error 1 Answer