Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
avatar image
2
Question by tocu-adrian · Jan 11, 2019 at 10:29 AM · unity 5rotationinspectoreuleranglesangles

How to get inspector rotation values ?

Hi, In my app i assembly some car parts and i want to check if the rotation of my object is right. Here are parts of my code:

  private void Update()
 {
     Debug.Log("x: " + Helper.WrapAngle(gameObject.transform.localEulerAngles.x));

     Debug.Log("y: " + Helper.WrapAngle(gameObject.transform.localEulerAngles.y));

     Debug.Log("z: " + Helper.WrapAngle(gameObject.transform.localEulerAngles.z));
 }

My WrapAngle:

  public static float WrapAngle(float angle)
 {
     angle %= 360;
     if (angle > 360)
         return angle - 360;

     return angle;
 }

I get something like this:

alt text

I want to get the same values as the Inspector rotation. Is it possible ? Thank you!

screenshot-2.png (49.7 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
11
Best Answer

Answer by tocu-adrian · Jan 11, 2019 at 12:04 PM

I found a solution:

   var x = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).x;
     var y = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).y;
     var z = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).z;

     Debug.Log("x: " + x);

     Debug.Log("y: " + y);

     Debug.Log("z: " + z);

I get what i want with this.

Comment
Add comment · Show 3 · Share
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
avatar image musmost · Jul 21, 2020 at 03:19 AM 0
Share

Yo thank you so much for this. I have been looking for it for hours. And they all keep talking about how you should understand quaternion to do it

avatar image ugurberkecanunlu · Jul 23, 2020 at 08:13 PM 1
Share

Its not working when I build the game. I want to use these values in my game.

avatar image yavuzyayla · Aug 19, 2020 at 09:31 AM 1
Share

This solution is using "UnityEditor" namespace. This namespace works only in Unity Editor and will not work in a builded game.

avatar image
0

Answer by haruna9x · Jan 11, 2019 at 11:52 AM

Let's review: 1. You are using the local rotation of the object, while Inspector is displaying the rotation of the object's world.

  1. WrapAngle as I see it doesn't seem to work as you want.

I wrote it before:

    public static float Clamp0360(float eulerAngles)
      {
          float result = eulerAngles - Mathf.CeilToInt(eulerAngles / 360f) * 360f;
          if (result < 0)
          {
              result += 360f;
          }
          return result;
      }
Comment
Add comment · Show 2 · Share
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
avatar image tocu-adrian · Jan 11, 2019 at 12:03 PM 0
Share

Thank you for your replay.

avatar image Wamoga · Mar 02 at 05:39 PM 1
Share

false? the inspector display based on parents ,not world?

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.

Follow this Question

Answers Answers and Comments

224 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation losing precision 0 Answers

Rotation angles not corresponding (inspector, debugging) 0 Answers

Why is my transform.rotatearound reset only working on positive Y? 0 Answers

Whats the Difference Between Rotation EulerAngles and Quaternions? 2 Answers

localEulerAngles.x changes when the angle is close to -90 in the inspector 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges