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. Dismiss Notice

Why isn't my GUI showing?

Discussion in 'Scripting' started by keenanwoodall, Jul 22, 2014.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    The GUI starting at line 65 doesn't show. I have no idea why. I feel like I'm missing something obvious though
    Code (csharp):
    1.  
    2. class TransformInspector extends Editor
    3. {
    4.     //Make a function that replaces the Transform Component in the Inpector
    5.     public override function  OnInspectorGUI ()
    6.     {
    7.         //target is the object you have selected in the editor. We are making a variable that is equal to the target's transform
    8.         var t : Transform = target.transform;
    9.         //Below we are creating new buttons on the Transform component
    10.         GUILayout.BeginHorizontal();
    11.         if (GUILayout.Button("P"))
    12.         {
    13.             //Here we are telling Unity that the stuff that's being done by this button (changing the transform) needs to be undo-able
    14.             Undo.RegisterUndo (t, "Reset Position " + t.name);
    15.             t.transform.position = Vector3(0,0,0);
    16.         }
    17.         if (GUILayout.Button("R"))
    18.         {
    19.             Undo.RegisterUndo (t, "Reset Rotation " + t.name);
    20.             t.transform.localEulerAngles = Vector3(0,0,0);
    21.         }
    22.         if (GUILayout.Button("S"))
    23.         {
    24.             Undo.RegisterUndo (t, "Reset Scale " + t.name);
    25.             t.transform.localScale = Vector3 (1,1,1);
    26.         }
    27.         if (GUILayout.Button("PRS"))
    28.         {
    29.             Undo.RegisterUndo (t, "Reset All " + t.name);
    30.             t.transform.position = Vector3(0,0,0);
    31.             t.transform.localEulerAngles = Vector3(0,0,0);
    32.             t.transform.localScale = Vector3 (1,1,1);
    33.         }
    34.         if (GUILayout.Button("Values To Integers"))
    35.         {
    36.             Undo.RegisterUndo (t, "Make To Whole Numbers " + t.name);
    37.             var xPosition : int = t.localPosition.x;
    38.             var yPosition : int = t.localPosition.y;
    39.             var zPosition : int = t.localPosition.z;
    40.             var xRotation : int = t.localEulerAngles.x;
    41.             var yRotation : int = t.localEulerAngles.y;
    42.             var zRotation : int = t.localEulerAngles.z;
    43.             var xScale : int = t.localScale.x;
    44.             var yScale : int = t.localScale.y;
    45.             var zScale : int = t.localScale.z;
    46.             t.localPosition.x = xPosition;
    47.             t.localPosition.y = yPosition;
    48.             t.localPosition.z = zPosition;
    49.             t.localEulerAngles.x = xRotation;
    50.             t.localEulerAngles.y = yRotation;
    51.             t.localEulerAngles.z = zRotation;
    52.             t.localScale.x = xScale;
    53.             t.localScale.y = yScale;
    54.             t.localScale.z = zScale;
    55.         }
    56.         GUILayout.EndHorizontal();
    57.         //Because we are overriding the transform components GUI in the Inspector, we have to recreate it below
    58.         //Here we are recreating the part of the Transform component that gave you acces to the position.
    59.         var position : Vector3 = EditorGUILayout.Vector3Field("Position", t.localPosition);
    60.         //Here we are recreating the part of the Transform component that gave you acces to the rotation.
    61.         var rotation : Vector3 = EditorGUILayout.Vector3Field("Rotation", t.localEulerAngles);
    62.         //Here we are recreating the part of the Transform component that gave you acces to the rotation.
    63.         var scale : Vector3 = EditorGUILayout.Vector3Field("Scale", t.localScale);
    64.        
    65.         var foldoutOpen : boolean = false;
    66.         foldoutOpen = EditorGUILayout.Foldout(foldoutOpen,"Quick Buttons")
    67.             GUILayout.Label ("Position");
    68.            GUILayout.BeginHorizontal();
    69.                if (GUILayout.Button("X-5"))
    70.                {
    71.                   position.x -= 5.0;
    72.                }
    73.                if (GUILayout.Button("X+5"))
    74.                {
    75.                   position.x += 5.0;
    76.                }
    77.                if (GUILayout.Button("Y-5"))
    78.                {
    79.                   position.y -= 5.0;
    80.                }
    81.                if (GUILayout.Button("Y+5"))
    82.                {
    83.                   position.y += 5.0;
    84.                }
    85.                if (GUILayout.Button("Z-5"))
    86.                {
    87.                   position.z -= 5.0;
    88.                }
    89.                if (GUILayout.Button("Z+5"))
    90.                {
    91.                   position.z += 5.0;
    92.                }
    93.            GUILayout.EndHorizontal();
    94.            GUILayout.Label ("Rotation");
    95.            GUILayout.BeginHorizontal();
    96.                if (GUILayout.Button("X-5"))
    97.                {
    98.                   rotation.x -= 5.0;
    99.                }
    100.                if (GUILayout.Button("X+5"))
    101.                {
    102.                   rotation.x += 5.0;
    103.                }
    104.                if (GUILayout.Button("Y-5"))
    105.                {
    106.                   rotation.y -= 5.0;
    107.                }
    108.                if (GUILayout.Button("Y+5"))
    109.                {
    110.                   rotation.y += 5.0;
    111.                }
    112.                if (GUILayout.Button("Z-5"))
    113.                {
    114.                   rotation.z -= 5.0;
    115.                }
    116.                if (GUILayout.Button("Z+5"))
    117.                {
    118.                   rotation.z += 5.0;
    119.                }
    120.            GUILayout.EndHorizontal();
    121.         //Here we are making a vector field that lets us offset the handles in the editor
    122.         if (GUI.changed)
    123.         {
    124.             Undo.RegisterUndo (t, "Transform Change");
    125.             t.localPosition = FixIfNaN(position);
    126.             t.localEulerAngles = FixIfNaN(rotation);
    127.             t.localScale = FixIfNaN(scale);
    128.         }
    129.     }
    130.     private function FixIfNaN(v : Vector3)
    131.     {
    132.         if (v.x == null)
    133.         {
    134.             v.x = 0;
    135.         }
    136.         if (v.y == null)
    137.         {
    138.             v.y = 0;
    139.         }
    140.         if (v.z == null)
    141.         {
    142.             v.z = 0;
    143.         }
    144.         return v;
    145.     }
    146. }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Are you saying that the GUI up to line 65 does show? Or, is none of it showing at all? I'd be surprised if anything was showing at all - in order to have this act as an Inspector, you need to have the CustomEditor attribute on the class:
    Code (csharp):
    1.  
    2. [CustomEditor(typeof(Transform))]
    3. class TransformInspector extends Editor
    4. {
    5.  
     
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    sorry for being unclear. The GUI after 65 doesn't show. Or more specifically, the GUI foldout
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Any error messages in the console?

    Would probably help to have a screenshot of what DOES show up.
     
  5. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    A foldout is used to show a tree of strings, not a group of buttons
     
  6. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    ok, how could I do a foldout of buttons..is it possible? It seems silly that a foldout is limited to Strings
     
  7. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Use a toggle?

    Code (CSharp):
    1. m_quickButtonsActive = EditorGUILayout.Toggle("Quick Buttons",m_quickButtonsActive );
    2.  
    3. if(m_quickButtonsActive)
    4. {
    5.   DrawButtons();
    6. }
     
  8. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    ok, I'll try that out
     
  9. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    no errors, the buttons just don't show up
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Is TransformInspector.cs in a folder named Editor, or in a subfolder of an Editor folder?
     
  11. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    So now the toggle shows, but I can't figure out a way to declare the boolean that sets the toggle without making the toggle always active or always deactivated.
    Code (csharp):
    1.  
    2. var foldoutOpen : boolean;
    3.         //foldoutOpen = EditorGUILayout.Toggle("Quick Buttons", foldoutOpen);
    4.         foldoutOpen = GUILayout.Toggle(foldoutOpen, "Quick Buttons");
    5.         if (foldoutOpen)
    6.         {
    7.               GUILayout.Label ("Position");
    8.               GUILayout.BeginHorizontal();
    9.                   if (GUILayout.Button("X-5"))
    10.                   {
    11.                      position.x -= 5.0;
    12.                   }
    13.                   if (GUILayout.Button("X+5"))
    14.                   {
    15.                      position.x += 5.0;
    16.                   }
    17.                   if (GUILayout.Button("Y-5"))
    18.                   {
    19.                      position.y -= 5.0;
    20.                   }
    21.                   if (GUILayout.Button("Y+5"))
    22.                   {
    23.                      position.y += 5.0;
    24.                   }
    25.                   if (GUILayout.Button("Z-5"))
    26.                   {
    27.                      position.z -= 5.0;
    28.                   }
    29.                   if (GUILayout.Button("Z+5"))
    30.                   {
    31.                      position.z += 5.0;
    32.                   }
    33.               GUILayout.EndHorizontal();
    34.               GUILayout.Label ("Rotation");
    35.               GUILayout.BeginHorizontal();
    36.                   if (GUILayout.Button("X-5"))
    37.                   {
    38.                      rotation.x -= 5.0;
    39.                   }
    40.                   if (GUILayout.Button("X+5"))
    41.                   {
    42.                      rotation.x += 5.0;
    43.                   }
    44.                   if (GUILayout.Button("Y-5"))
    45.                   {
    46.                      rotation.y -= 5.0;
    47.                   }
    48.                   if (GUILayout.Button("Y+5"))
    49.                   {
    50.                      rotation.y += 5.0;
    51.                   }
    52.                   if (GUILayout.Button("Z-5"))
    53.                   {
    54.                      rotation.z -= 5.0;
    55.                   }
    56.                   if (GUILayout.Button("Z+5"))
    57.                   {
    58.                      rotation.z += 5.0;
    59.                   }
    60.               GUILayout.EndHorizontal();
    61.        }
     
  12. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    Its javascript
     
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    In that case:

    Is TransformInspector.js in a folder named Editor, or in a subfolder of an Editor folder?
     
  14. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    yes
     
  15. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    This is the UnityScript syntax for custom editors, you picked the C# one:
    Code (csharp):
    1. @CustomEditor(Transform)
    Also make sure you have a semicolon at the end of this line (already added it here):
    Code (csharp):
    1. foldoutOpen = EditorGUILayout.Foldout(foldoutOpen,"Quick Buttons");
     
  16. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    Ok thanks, but that I still don't know how to fix the toggle
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It would really make sense if you could post a script that actually compiles. Like that you are not wasting your own or our time. Post exactly what you have!

    You defined foldoutOpen as a local variable which is always lost. You have to declare it as an instance variable that is preserved.

    Code (csharp):
    1. @CustomEditor(Transform)
    2.  
    3. class TransformInspector extends Editor
    4. {
    5.    var foldoutOpen : boolean;
    6.  
    7.    //Make a function that replaces the Transform Component in the Inpector
    8.    public override function   OnInspectorGUI ()
    9.    {
    10.      //target is the object you have selected in the editor. We are making a variable that is equal to the target's transform
    11.      var t : Transform = target.transform;
    12.      //Below we are creating new buttons on the Transform component
    13.      GUILayout.BeginHorizontal();
    14.      if (GUILayout.Button("P"))
    15.      {
    16.        //Here we are telling Unity that the stuff that's being done by this button (changing the transform) needs to be undo-able
    17.        Undo.RegisterUndo (t, "Reset Position " + t.name);
    18.        t.transform.position = Vector3(0,0,0);
    19.      }
    20.      if (GUILayout.Button("R"))
    21.      {
    22.        Undo.RegisterUndo (t, "Reset Rotation " + t.name);
    23.        t.transform.localEulerAngles = Vector3(0,0,0);
    24.      }
    25.      if (GUILayout.Button("S"))
    26.      {
    27.        Undo.RegisterUndo (t, "Reset Scale " + t.name);
    28.        t.transform.localScale = Vector3 (1,1,1);
    29.      }
    30.      if (GUILayout.Button("PRS"))
    31.      {
    32.        Undo.RegisterUndo (t, "Reset All " + t.name);
    33.        t.transform.position = Vector3(0,0,0);
    34.        t.transform.localEulerAngles = Vector3(0,0,0);
    35.        t.transform.localScale = Vector3 (1,1,1);
    36.      }
    37.      if (GUILayout.Button("Values To Integers"))
    38.      {
    39.        Undo.RegisterUndo (t, "Make To Whole Numbers " + t.name);
    40.        var xPosition : int = t.localPosition.x;
    41.        var yPosition : int = t.localPosition.y;
    42.        var zPosition : int = t.localPosition.z;
    43.        var xRotation : int = t.localEulerAngles.x;
    44.        var yRotation : int = t.localEulerAngles.y;
    45.        var zRotation : int = t.localEulerAngles.z;
    46.        var xScale : int = t.localScale.x;
    47.        var yScale : int = t.localScale.y;
    48.        var zScale : int = t.localScale.z;
    49.        t.localPosition.x = xPosition;
    50.        t.localPosition.y = yPosition;
    51.        t.localPosition.z = zPosition;
    52.        t.localEulerAngles.x = xRotation;
    53.        t.localEulerAngles.y = yRotation;
    54.        t.localEulerAngles.z = zRotation;
    55.        t.localScale.x = xScale;
    56.        t.localScale.y = yScale;
    57.        t.localScale.z = zScale;
    58.      }
    59.      GUILayout.EndHorizontal();
    60.      //Because we are overriding the transform components GUI in the Inspector, we have to recreate it below
    61.      //Here we are recreating the part of the Transform component that gave you acces to the position.
    62.      var position : Vector3 = EditorGUILayout.Vector3Field("Position", t.localPosition);
    63.      //Here we are recreating the part of the Transform component that gave you acces to the rotation.
    64.      var rotation : Vector3 = EditorGUILayout.Vector3Field("Rotation", t.localEulerAngles);
    65.      //Here we are recreating the part of the Transform component that gave you acces to the rotation.
    66.      var scale : Vector3 = EditorGUILayout.Vector3Field("Scale", t.localScale);
    67.      
    68.    
    69.      foldoutOpen = EditorGUILayout.Foldout(foldoutOpen,"Quick Buttons");
    70.      if (foldoutOpen)
    71.      {
    72.        GUILayout.Label ("Position");
    73.        GUILayout.BeginHorizontal();
    74.          if (GUILayout.Button("X-5"))
    75.          {
    76.            position.x -= 5.0;
    77.          }
    78.          if (GUILayout.Button("X+5"))
    79.          {
    80.            position.x += 5.0;
    81.          }
    82.          if (GUILayout.Button("Y-5"))
    83.          {
    84.            position.y -= 5.0;
    85.          }
    86.          if (GUILayout.Button("Y+5"))
    87.          {
    88.            position.y += 5.0;
    89.          }
    90.          if (GUILayout.Button("Z-5"))
    91.          {
    92.            position.z -= 5.0;
    93.          }
    94.          if (GUILayout.Button("Z+5"))
    95.          {
    96.            position.z += 5.0;
    97.          }
    98.        GUILayout.EndHorizontal();
    99.        GUILayout.Label ("Rotation");
    100.        GUILayout.BeginHorizontal();
    101.          if (GUILayout.Button("X-5"))
    102.          {
    103.            rotation.x -= 5.0;
    104.          }
    105.          if (GUILayout.Button("X+5"))
    106.          {
    107.            rotation.x += 5.0;
    108.          }
    109.          if (GUILayout.Button("Y-5"))
    110.          {
    111.            rotation.y -= 5.0;
    112.          }
    113.          if (GUILayout.Button("Y+5"))
    114.          {
    115.            rotation.y += 5.0;
    116.          }
    117.          if (GUILayout.Button("Z-5"))
    118.          {
    119.            rotation.z -= 5.0;
    120.          }
    121.          if (GUILayout.Button("Z+5"))
    122.          {
    123.            rotation.z += 5.0;
    124.          }
    125.        GUILayout.EndHorizontal();
    126.      }
    127.      //Here we are making a vector field that lets us offset the handles in the editor
    128.      if (GUI.changed)
    129.      {
    130.        Undo.RegisterUndo (t, "Transform Change");
    131.        t.localPosition = FixIfNaN(position);
    132.        t.localEulerAngles = FixIfNaN(rotation);
    133.        t.localScale = FixIfNaN(scale);
    134.      }
    135.    }
    136.    
    137.    private function FixIfNaN(v : Vector3)
    138.    {
    139.      if (v.x == null)
    140.      {
    141.        v.x = 0;
    142.      }
    143.      if (v.y == null)
    144.      {
    145.        v.y = 0;
    146.      }
    147.      if (v.z == null)
    148.      {
    149.        v.z = 0;
    150.      }
    151.      return v;
    152.    }
    153. }
     
  18. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    Whenever I declare it somewhere else (anywhere that it wont be a local variable, constantly changed to its declared state), it gives me an error and doesn't recognize the variable when I instance it at the toggle
    Code (csharp):
    1.  
    2. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3. //                                                                                                                                        //
    4. //                                                                                                                                        //
    5. //                                                                                                                                        //                                                                                                                                //
    6. //                    This script was created by Keenan Woodall, for personal use and is now available for anyone to use,                    //
    7. //                    modify, share, or tweak. If you share this script, give credit to Keenan Woodall.                                     //
    8. //                    Keenan made this script and made it free, to help others out.                                                        //
    9. //                    You are welcome to use this commercially. You don't have to put me in the credits or anything.                         //
    10. //                    I would love it if you email me at keenanwoodall@gmail.com if you do use this in making a game.                     //
    11. //                    I'd love to check it out! I hope you enjoy this asset, and if you have any feedback, you can email me,                //
    12. //                    or comment on the asset store. This is a continous project that will be updated as I add features/content.             //
    13. //                                                                                                                                        //
    14. //                                                                                                                                        //
    15. //                                                                                                                                        //
    16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    17. @CustomEditor (Transform)
    18.  
    19. class TransformInspector extends Editor
    20. {
    21.     //Make a function that replaces the Transform Component in the Inpector
    22.     public override function  OnInspectorGUI ()
    23.     {
    24.         //target is the object you have selected in the editor. We are making a variable that is equal to the target's transform
    25.         var t : Transform = target.transform;
    26.         //Below we are creating new buttons on the Transform component
    27.         GUILayout.BeginHorizontal();
    28.         if (GUILayout.Button("P"))
    29.         {
    30.             //Here we are telling Unity that the stuff that's being done by this button (changing the transform) needs to be undo-able
    31.             Undo.RegisterUndo (t, "Reset Position " + t.name);
    32.             t.transform.position = Vector3(0,0,0);
    33.         }
    34.         if (GUILayout.Button("R"))
    35.         {
    36.             Undo.RegisterUndo (t, "Reset Rotation " + t.name);
    37.             t.transform.localEulerAngles = Vector3(0,0,0);
    38.         }
    39.         if (GUILayout.Button("S"))
    40.         {
    41.             Undo.RegisterUndo (t, "Reset Scale " + t.name);
    42.             t.transform.localScale = Vector3 (1,1,1);
    43.         }
    44.         if (GUILayout.Button("PRS"))
    45.         {
    46.             Undo.RegisterUndo (t, "Reset All " + t.name);
    47.             t.transform.position = Vector3(0,0,0);
    48.             t.transform.localEulerAngles = Vector3(0,0,0);
    49.             t.transform.localScale = Vector3 (1,1,1);
    50.         }
    51.         if (GUILayout.Button("Values To Integers"))
    52.         {
    53.             Undo.RegisterUndo (t, "Make To Whole Numbers " + t.name);
    54.             var xPosition : int = t.localPosition.x;
    55.             var yPosition : int = t.localPosition.y;
    56.             var zPosition : int = t.localPosition.z;
    57.             var xRotation : int = t.localEulerAngles.x;
    58.             var yRotation : int = t.localEulerAngles.y;
    59.             var zRotation : int = t.localEulerAngles.z;
    60.             var xScale : int = t.localScale.x;
    61.             var yScale : int = t.localScale.y;
    62.             var zScale : int = t.localScale.z;
    63.             t.localPosition.x = xPosition;
    64.             t.localPosition.y = yPosition;
    65.             t.localPosition.z = zPosition;
    66.             t.localEulerAngles.x = xRotation;
    67.             t.localEulerAngles.y = yRotation;
    68.             t.localEulerAngles.z = zRotation;
    69.             t.localScale.x = xScale;
    70.             t.localScale.y = yScale;
    71.             t.localScale.z = zScale;
    72.         }
    73.         GUILayout.EndHorizontal();
    74.         //Because we are overriding the transform components GUI in the Inspector, we have to recreate it below
    75.         EditorGUIUtility.LookLikeControls();
    76.         EditorGUI.indentLevel = 0;
    77.         //Here we are recreating the part of the Transform component that gave you acces to the position.
    78.         var position : Vector3 = EditorGUILayout.Vector3Field("Position", t.localPosition);
    79.         //Here we are recreating the part of the Transform component that gave you acces to the rotation.
    80.         var rotation : Vector3 = EditorGUILayout.Vector3Field("Rotation", t.localEulerAngles);
    81.         //Here we are recreating the part of the Transform component that gave you acces to the rotation.
    82.         var scale : Vector3 = EditorGUILayout.Vector3Field("Scale", t.localScale);
    83.        
    84.         var foldoutOpen : boolean;
    85.         //foldoutOpen = EditorGUILayout.Toggle("Quick Buttons", foldoutOpen);
    86.         foldoutOpen = GUILayout.Toggle(foldoutOpen, "Quick Buttons");
    87.         if (foldoutOpen)
    88.         {
    89.               GUILayout.Label ("Position");
    90.               GUILayout.BeginHorizontal();
    91.                   if (GUILayout.Button("X-5"))
    92.                   {
    93.                      position.x -= 5.0;
    94.                   }
    95.                   if (GUILayout.Button("X+5"))
    96.                   {
    97.                      position.x += 5.0;
    98.                   }
    99.                   if (GUILayout.Button("Y-5"))
    100.                   {
    101.                      position.y -= 5.0;
    102.                   }
    103.                   if (GUILayout.Button("Y+5"))
    104.                   {
    105.                      position.y += 5.0;
    106.                   }
    107.                   if (GUILayout.Button("Z-5"))
    108.                   {
    109.                      position.z -= 5.0;
    110.                   }
    111.                   if (GUILayout.Button("Z+5"))
    112.                   {
    113.                      position.z += 5.0;
    114.                   }
    115.               GUILayout.EndHorizontal();
    116.               GUILayout.Label ("Rotation");
    117.               GUILayout.BeginHorizontal();
    118.                   if (GUILayout.Button("X-5"))
    119.                   {
    120.                      rotation.x -= 5.0;
    121.                   }
    122.                   if (GUILayout.Button("X+5"))
    123.                   {
    124.                      rotation.x += 5.0;
    125.                   }
    126.                   if (GUILayout.Button("Y-5"))
    127.                   {
    128.                      rotation.y -= 5.0;
    129.                   }
    130.                   if (GUILayout.Button("Y+5"))
    131.                   {
    132.                      rotation.y += 5.0;
    133.                   }
    134.                   if (GUILayout.Button("Z-5"))
    135.                   {
    136.                      rotation.z -= 5.0;
    137.                   }
    138.                   if (GUILayout.Button("Z+5"))
    139.                   {
    140.                      rotation.z += 5.0;
    141.                   }
    142.               GUILayout.EndHorizontal();
    143.        }
    144.        
    145.         //Here we are making a vector field that lets us offset the handles in the editor
    146.         EditorGUIUtility.LookLikeInspector();
    147.         if (GUI.changed)
    148.         {
    149.             Undo.RegisterUndo (t, "Transform Change");
    150.             t.localPosition = FixIfNaN(position);
    151.             t.localEulerAngles = FixIfNaN(rotation);
    152.             t.localScale = FixIfNaN(scale);
    153.         }
    154.     }
    155.     private function FixIfNaN(v : Vector3)
    156.     {
    157.         if (v.x == null)
    158.         {
    159.             v.x = 0;
    160.         }
    161.         if (v.y == null)
    162.         {
    163.             v.y = 0;
    164.         }
    165.         if (v.z == null)
    166.         {
    167.             v.z = 0;
    168.         }
    169.         return v;
    170.     }
    171. }
     
  19. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I already posted the solution in the previous script. The magic line in number 5.
     
  20. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    O, sorry man I didn't see that. Sorry for making this hard! It works perfectly now :)