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

How to rotate a Game object using mouse scroll wheel?

Discussion in 'Editor & General Support' started by Mathsunitt, Apr 19, 2014.

  1. Mathsunitt

    Mathsunitt

    Joined:
    Apr 13, 2014
    Posts:
    8
    Hello! I am trying to rotate the angle X of my Game Object using the scroll wheel.
    I've done a simple script to detect the scroll wheel movement:

    Code (csharp):
    1. if (Input.GetAxis("Mouse ScrollWheel") > 0) { // rotation script }
    Now I need to rotate my Game Object in Angle X.
    Thanks.
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  3. Mathsunitt

    Mathsunitt

    Joined:
    Apr 13, 2014
    Posts:
    8
    Hello, I got the result using the following code:

    Code (csharp):
    1. if (Input.GetAxis("Mouse ScrollWheel") > 0) {
    2.     transform.Rotate(Vector3.left * 0.5f, Space.Self);
    3. }
    4. if (Input.GetAxis("Mouse ScrollWheel") < 0) {
    5.     transform.Rotate(Vector3.right * 0.5f, Space.Self);
    6. }
    Thanks for the replies.
     
    dappertech and Lavaflame like this.
  4. dominosinco

    dominosinco

    Joined:
    Apr 23, 2019
    Posts:
    2
    Code (CSharp):
    1.             if (Input.mouseScrollDelta.y != 0)
    2.             {
    3.                 transform.Rotate(Vector3.right * Input.mouseScrollDelta.y);
    4.             }
    im a lil late