Rotate GameObject using mouse drag or touch: Unity Tutorial

This article explains how to rotate GameObject using mouse drag or touch in unity applications.

For the example, I have created a sample unity project and added a simple cube GameObject in the scene.Rotate GameObject using mouse drag or touch - Scene

Rotate GameObject using mouse drag or touch

Attach the below given script to the GameObject that you want to rotate. I have attached it to the cube GameObject.

Now, run the application and try to rotate cube using mouse drag.

Rotate GameObject using mouse drag or touch - Mouse drag

Build the project for android platform and install it in android device. I have tested it with android Marshmallow and the rotation was working fine.

Rotate GameObject using mouse drag or touch - android

Hope, you get an idea to rotate Gameobject on mouse drag or touch in unity application. Post your comments for queries and feedback. Thanks for reading.

Share Button
The following two tabs change content below.
Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

Gyanendu Shekhar

Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

One thought on “Rotate GameObject using mouse drag or touch: Unity Tutorial

  • July 2, 2018 at 4:18 pm
    Permalink

    How can we get exactly same rotation as we see in the prefab preview window?
    I mean, when we select the prefab from the project tab then a window shows that prefab from where we can rotate that prefab…

    Waiting for your reply
    thanks.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *