Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question C# doesn't work with blender Model

Discussion in 'Animation' started by micmazzotta, Feb 7, 2023.

  1. micmazzotta

    micmazzotta

    Joined:
    Jan 10, 2023
    Posts:
    5
    hi,
    I am practicing with unity 2021.3.14f1. I imported unity a model created with Blender, the object is with .blender extension.
    I would like to rotate the object with click and mouse movement. I wrote this code in c#:

    Code (CSharp):
    1. public class BodyRotation : MonoBehaviour
    2. {
    3.  
    4.     float speed = 20;
    5.  
    6.     //rotation command
    7.      void OnMouseDrag()
    8.     {
    9.         float rotX = Input.GetAxis("Mouse X") * speed * Mathf.Deg2Rad;
    10.         float rotY = Input.GetAxis("Mouse Y") * speed * Mathf.Deg2Rad;
    11.         float rotZ = Input.GetAxis("Mouse Z") * speed * Mathf.Deg2Rad;
    12.  
    13.         transform.Rotate(Vector3.up, -rotX);
    14.         transform.Rotate(Vector3.right, rotY);
    15.         transform.Rotate(Vector3.forward, rotZ);
    16.     }
    17. }
    the code on a normal 3d object created within Unity works, but when I apply it to the model created with Blender it doesn't work.
    What did I do wrong?

    Thanks
     
  2. micmazzotta

    micmazzotta

    Joined:
    Jan 10, 2023
    Posts:
    5
    I solved by inserting the blender model inside a 3d cube, created in Unity, then made transparent. Could this be a good solution or could it give me problems with interactivity?