Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotaion of the object

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

  1. Macode

    Macode

    Joined:
    Nov 28, 2013
    Posts:
    38
    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