Mouse drag rotation script doesn't work when attached to OBJ model

I am new to Unity. I imported an OBJ model and assigned materials to it.

I want to rotate it using the mouse in the game, using this script:

using UnityEngine;

public class MouseDragRotate : MonoBehaviour {
float rotationSpeed = 0.2f;

void OnMouseDrag()
{
float XaxisRotation = Input.GetAxis("Mouse X")*rotationSpeed;
float YaxisRotation = Input.GetAxis("Mouse Y")*rotationSpeed;
// select the axis by which you want to rotate the GameObject
transform.RotateAround (Vector3.down, XaxisRotation);
transform.RotateAround (Vector3.right, YaxisRotation);
}
}


I tried to apply this rotation script to the OBJ asset in my Project folder, but I wasn't able to find an Add Component option in its Inspector.

So I dragged it to the Hierarchy panel to create an instance of the object in my scene. I applied my materials again to this instance.

Then I added the rotation script using the Add Component button in the Inspector.

But when running the game in play mode, I can't rotate it.

I verified that the script above works perfectly for the default Cube or Plane primitives in Unity, but not for this imported object.

How can I make this script work with my OBJ model?

• It sounds like you probably added your rotation component to the wrong object in your hierarchy - say an empty child object instead of the parent of the mesh. Or you could be using a material that overrides the object's transformation matrix. Unfortunately, knowing only that the object was from an OBJ file, and that you applied some unspecified materials to it, doesn't give us enough information to reproduce this problem in a new project. Can you walk us through the steps we need to follow to see the same error you're seeing? – DMGregory Jun 20 '19 at 11:36
• Is it safe to assume your object has a Collider to detect when the mouse is clicking / dragging over it, so Unity knows to call OnMouseDrag on that object's scripts? – DMGregory Jun 20 '19 at 11:38
• @DMGregory I added the box Collider manually now it working .. Thanks – Lord Commander Jun 20 '19 at 11:50
• please add a detailed answer about box collider and its working principle and uses – Lord Commander Jun 20 '19 at 11:51
• I will accept and upvote and others user will get benefited – Lord Commander Jun 20 '19 at 11:51