reset -----> transform.Rotate( 0, 0, 0 );

Hi …
I need help on script to reset to ( 0,0,0 ) an object by pressing a button.

in other words …
when user press this button

if (GUI.Button( Rect( 10, 10, 80, 80), “RESET ROTATION”))
{ }

Please I need the object RETURN to the (rotate) starting position (0,0,0)
could be possible?

Thanks in advance.

theGameObject.transform.rotation = Quaternion.identity;

4 Likes
var TargetObject:Transform;

function OnGUI(){
if (GUI.Button( Rect( 10, 10, 80, 80), "RESET ROTATION"))
  {
    TargetObject.Rotation=Quaternion.Euler(Vector3(0,0,0);
  }
}

so all im diong is assing the target object to the variable TargetObject, it then grabs the rotation of it. Quaternion is just the rotation class, and Euler changes the new Vector3 to a rotation value, so it assigns it to the rotation (0,0,0)

thanks a lot
thanks you very much.

I tried this and it doesn’t work. For some reason there is a missing field exception because of the transform.Rotation script. I would think it would work because the script is pretty straight forward, but I was wrong. Any suggestions?

There’s a typo in the script above. The line:
TargetObject.Rotation=Quaternion.Euler(Vector3(0,0,0);

Should be:
TargetObject.Rotation=Quaternion.Euler(Vector3(0,0,0));

Or:
TargetObject.Rotation= Quaternion.identity;

Not a single thing in this list worked for me
Absolute lies ;-;

1 Like

@SpectrumHandsome_YT

“Not a single thing in this list worked for me”

You are replying to a thread from 2010…

Which was last time resurrected in 2013…

And some of the code is written in a language that is no longer used in Unity (Unity script).
“Absolute lies ;-;”

You can still use IMGUI UI for editor scripting. But you’ll have to write everything in C# language.

And this one still pretty much works as is, as long as you have a gameObject called theGameObject in your script or if you remove the theGameObject part:
theGameObject.transform.rotation = Quaternion.identity;

3 Likes

Hi I’m looking to smoothly rotate. Hello from 2021! :slight_smile:

Are we just recreationally necroposting now?
Make your own post, ask your question, add the details of what you’re trying to do in your situation, we cannot possibly help you with the sentence “I’m looking to smoothly rotate”.

3 Likes

Yes, but Joanie from “Happy Days” can. She would tell you that the first step is to sit on it.

2 Likes