How to apply script to a imported OBJ file in unity?


#1

I am new to unity

I imported a OBJ model and assigned materials to it

I want to rotate it using mouse in the game

The script is :

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);
    }
}

Then I tried to apply a script for rotation but add component not found the inspection menu

So i dragged it to the Hierarchy panel

It was re created again

Then I applied materials again

Then I added the rotation script using add component . But when running the game in play mode , I can’t rotate it

So I created a cube and plane and applied the script

The script works perfectly for cube and plane but not for imported object

please help me