How to get rotation of an object using C#

This is the code that I have written to get an object rotation

71129-capture.png

The object’s X rotation is 45

71130-capture2.png

But on the console I am getting 0.3826835

In the code I have written local rotation but I want global rotation

c.transform.location is a quaternion In theinspector, the rotation is shown in euler angles

3 Answers

3

c.transform.localRotation.eulerAngles.x

Thanks a lot, your code works.

This isn't working for me, I am getting a value not even close to the actual in inspector during runtime. Any changes? Please help

i am rotating object between 50 to-50 and getting value far from actual value, what is am missing ?

[PROBLEM SOLVED]

.

Skip all the above coments.

.

I found a way to get the exact rotation values as in INSPECTOR

.

.

I am showing for angle (x)

,The code is as follow

.

 public Transform GameObject;
 
 void Update()
 {
     float Rotation;
     if(GameObject.eulerAngles.x <= 180f)
     {
         Rotation = GameObject.eulerAngles.x;
     }
     else
     {
         Rotation = GameObject.eulerAngles.x - 360f;
     }
 }

this is the best!!! Thank you very much!!!

Have you tried using Visual Scripting or Bolt? if you are new to coding these could help with learning what things do and not so much did i spell something wrong. you can also watch your script in action as it runs.

Well I was thinking of simple city with only one instance of basic building (stadium, theatre, hospital, police station, school, swimming pool, etc. + some residential and industrial areas). I have see that some packages can be bought from 100 to 2000 $ on various modelling sites. Couldn't it be within that range ?