Created
May 9, 2016 14:47
-
-
Save yunojy/0fcee6d7ecafee107425cdbb30859ecf to your computer and use it in GitHub Desktop.
Unity Editor Like CameraControl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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