- Home /
Question by
BenoitFreslon · Jan 21, 2014 at 11:11 AM ·
shortcuts
Moving objects with keyboard shortcuts
Hello,
Are there keyboard shortcuts to move objects in the IDE?
Like CMD + Up Arrow.
Thanks
Comment
Answer by BenoitFreslon · Mar 17, 2014 at 06:15 PM
Thanks for the tips but the Input.GetKey is not woking on my script: #if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
class MoveGameObject {
static MoveGameObject () {
EditorApplication.update += Update;
}
static bool isCommandDown;
static void Update () {
//Debug.Log (Selection.activeGameObject);
if (Input.GetKeyDown (KeyCode.A)) {
Debug.Log ("key");
}
if (Input.GetKeyDown (KeyCode.LeftApple) || Input.GetKeyDown (KeyCode.RightApple)) {
Debug.Log ("keydown");
isCommandDown = true;
}
if (Input.GetKeyUp (KeyCode.LeftApple) || Input.GetKeyUp (KeyCode.RightApple)) {
Debug.Log ("keyup");
isCommandDown = false;
}
if (isCommandDown) {
GameObject go = Selection.activeGameObject;
Debug.Log (go);
if (go && Input.GetKeyDown (KeyCode.RightArrow)) {
go.transform.position += new Vector3 (1f, 0f, 0f);
}
if (go && Input.GetKeyDown (KeyCode.LeftArrow)) {
go.transform.position += new Vector3 (-1f, 0f, 0f);
}
}
}
}
#endif
Answer by komodor · Jan 21, 2014 at 11:26 AM
not in the IDE itself, but there are assets fro it surely
however you can do very simple piese of code whcih will basically check if there was pressed CMD and UpArrow in the same time and check for it on update
if (Input.GetKeyDown("nameofthekey"))
{
nameofthekey = true;
}
if (Input.GetKeyUp("nameofthekey"))
{
nameofthekey = false;
}
if (Input.GetKeyDown("nameofthekey2"))
{
nameofthekey2 = true;
}
if (Input.GetKeyUp("nameofthekey2"))
{
nameofthekey2 = false;
}
if (nameofthekey && nameofthekey2)
{
bothkeysarepressed = true;
}
else
{
bothkeysarepressed = false;
}