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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'Scripting' started by josemauriciob, Oct 15, 2010.

Thread Status:
Not open for further replies.
  1. josemauriciob

    josemauriciob

    Joined:
    Mar 5, 2009
    Posts:
    662
    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.
     
  2. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
  3. Dr_Fumi

    Dr_Fumi

    Joined:
    Jul 24, 2010
    Posts:
    50
    Code (csharp):
    1. var TargetObject:Transform;
    2.  
    3. function OnGUI(){
    4. if (GUI.Button( Rect( 10, 10, 80, 80), "RESET ROTATION"))
    5.   {
    6.     TargetObject.Rotation=Quaternion.Euler(Vector3(0,0,0);
    7.   }
    8. }
    9.  
    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)
     
  4. josemauriciob

    josemauriciob

    Joined:
    Mar 5, 2009
    Posts:
    662
    thanks a lot
    thanks you very much.
     
  5. Tuxedo Games

    Tuxedo Games

    Joined:
    Mar 11, 2013
    Posts:
    3
    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?
     
  6. Errorsatz

    Errorsatz

    Joined:
    Aug 8, 2012
    Posts:
    555
    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;
     
  7. SpectrumHandsome_YT

    SpectrumHandsome_YT

    Joined:
    Aug 29, 2020
    Posts:
    1
    Not a single thing in this list worked for me
    Absolute lies ;-;
     
    drewjosh likes this.
  8. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @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;

     
    Bunny83, Kurt-Dekker and misa67 like this.
  9. joeross0

    joeross0

    Joined:
    Dec 31, 2017
    Posts:
    8
    Hi I'm looking to smoothly rotate. Hello from 2021! :)
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    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".
     
    drewjosh, SuspecM and Bunny83 like this.
  11. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,925
    Yes, but Joanie from "Happy Days" can. She would tell you that the first step is to sit on it.
     
    Bunny83 and Kurt-Dekker like this.
Thread Status:
Not open for further replies.