Skip to content

Instantly share code, notes, and snippets.

@yunojy
Created May 9, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunojy/0fcee6d7ecafee107425cdbb30859ecf to your computer and use it in GitHub Desktop.
Save yunojy/0fcee6d7ecafee107425cdbb30859ecf to your computer and use it in GitHub Desktop.
Unity Editor Like CameraControl
using UnityEngine;
public class DebugCameraControl : MonoBehaviour {
#if UNITY_EDITOR
private Vector3 oldPos;
void Update() {
if (Input.GetMouseButton(1)) {
// 右クリック中にWASDでカメラ前後左右移動
transform.position += transform.forward * Input.GetAxis("Vertical") / 30f;
transform.position += transform.right * Input.GetAxis("Horizontal") / 30f;
// 右クリック中にQEでカメラ上下移動
float uppos = 0.0f;
if (Input.GetKey(KeyCode.Q)) uppos = -0.01f;
if (Input.GetKey(KeyCode.E)) uppos = 0.01f;
transform.position += transform.up * uppos;
// 右ドラッグでカメラ向き回転
var diff = Input.mousePosition - oldPos;
if (Mathf.Abs(diff.x) < 10f && Mathf.Abs(diff.y) < 10f) {
transform.RotateAround(Vector3.up, diff.x / 100f);
transform.RotateAround(transform.right, -diff.y / 100f);
}
oldPos = Input.mousePosition;
}
// スクロールでカメラ前後移動
transform.position += transform.forward * Input.GetAxis("Mouse ScrollWheel");
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment