Advertisement
BlackDragonBE

MoveWithArrowKeys.cs

Jul 28th, 2015
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. [ExecuteInEditMode]
  6. public class MoveWithArrowKeys : MonoBehaviour
  7. {
  8.     //References
  9.  
  10.     //Public
  11.     public float AmountToMove = 1f;
  12.     public static Transform staticTransform;
  13.     public static float staticAmountToMove;
  14.  
  15.     //Private
  16.  
  17. #if UNITY_EDITOR
  18.     void OnRenderObject()
  19.     {
  20.         if (!Application.isPlaying && Selection.activeGameObject != null)
  21.         {
  22.             staticTransform = Selection.activeGameObject.transform;
  23.         }
  24.         else
  25.         {
  26.             staticTransform = null;
  27.         }
  28.         staticAmountToMove = AmountToMove;
  29.     }
  30.  
  31.     [MenuItem("Edit/Move/Right %RIGHT")]
  32.     private static void MoveRight()
  33.     {
  34.         if (staticTransform)
  35.         staticTransform.Translate(Vector3.right * staticAmountToMove);
  36.     }
  37.  
  38.  
  39.     [MenuItem("Edit/Move/Right %LEFT")]
  40.     static void MoveLeft()
  41.     {
  42.         if (staticTransform)
  43.         staticTransform.Translate(Vector3.left * staticAmountToMove);
  44.     }
  45.  
  46.     [MenuItem("Edit/Move/Right %UP")]
  47.     static void MoveUp()
  48.     {
  49.         if (staticTransform)
  50.         staticTransform.Translate(Vector3.up * staticAmountToMove);
  51.     }
  52.  
  53.     [MenuItem("Edit/Move/Right %DOWN")]
  54.     static void MoveDown()
  55.     {
  56.         if (staticTransform)
  57.         staticTransform.Translate(Vector3.down * staticAmountToMove);
  58.     }
  59. #endif
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement