Search Unity

Rotaion of the object

Discussion in 'Scripting' started by Macode, Nov 28, 2013.

  1. Macode

    Macode

    Joined:
    Nov 28, 2013
    Posts:
    12
    Hi there.
    I need to rotate an object (game map) around z-axis around 90deg by pressing "A" key.
    I tried next:
    Code (csharp):
    1.  
    2. private bool is_rotating;
    3. void Update ()
    4.     {
    5.         if (Input.GetKeyDown(KeyCode.A)  (is_rotating == false))
    6.         {
    7.             is_rotating = true;
    8.         }
    9.                
    10.         if (is_rotating)
    11.                 rotate_map();
    12.     }
    13.    
    14. void rotate_map()
    15.     {
    16.         transform.Rotate(Vector3.forward * 90 * Time.deltaTime);
    17.     }
    18.  
    This script gives rotation to the object, but the value of transform.eulerAngles.z never reaches exact value 90, so I can't stop the rotation.
    Help please.
     
    Last edited: Nov 28, 2013
unityunity