• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by wale · Jan 19, 2016 at 08:59 AM · c#rotationonclick.fbx

Rotation to a .fbx model ...... on click rotation

I am new to unity .... I have a model with .fbx extension . The model is chair on that i tried a script like colour chaning to chair..... bt when i am trying for that onclick rotation it's not working ... ia am not getting whats getting ................ when the same code i use for cube from the game object it work grate.... i want to know what the problem with .fbx model of chair

Assets used for to implement this code is here https://www.assetstore.unity3d.com/en/#!/content/11859

It's a code for rotation : using UnityEngine; using System.Collections;

public class rotate : MonoBehaviour {

 private float baseAngle = 0.0f;
 
 void OnMouseDown(){
     Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
     pos = Input.mousePosition - pos;
     baseAngle = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
     baseAngle -= Mathf.Atan2(transform.right.y, transform.right.x) *Mathf.Rad2Deg;
 }
 
 void OnMouseDrag(){
     Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
     pos = Input.mousePosition - pos;
     float ang = Mathf.Atan2(pos.y, pos.x) *Mathf.Rad2Deg - baseAngle;
     transform.rotation = Quaternion.AngleAxis(ang, Vector3.forward);
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Access 2DCollision Torque/rotation force and set it to 0 0 Answers

Camera Rotation Around Player 1 Answer

.rotation doesn't seem to work, can't shoot projectile at mouse coordinates 0 Answers

How do you rotate the player and keep them there? 1 Answer

Trying to get Player Character to look at the mouse pointer... which i have done, but would like to smooth the rotation. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges