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?