Created
December 9, 2015 11:35
-
-
Save peroon/a991b3f78f8e02cd384c to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| using System.Collections; | |
| // Alt + マウス右クリックでカメラを動かす | |
| public class MouseCamera : MonoBehaviour { | |
| float oldMouseX = 0; | |
| float oldMouseY = 0; | |
| float mouseX = 0; | |
| float mouseY = 0; | |
| public float speedX = 1.0f; | |
| public float speedY = 1.0f; | |
| bool isMousePressed = false; | |
| void Update () { | |
| if (Input.GetMouseButtonDown (0)) { | |
| isMousePressed = true; | |
| oldMouseX = Input.GetAxis ("Mouse X"); | |
| oldMouseY = Input.GetAxis ("Mouse Y"); | |
| } | |
| if (Input.GetMouseButtonUp (0)) { | |
| isMousePressed = false; | |
| } | |
| // マウス押してる時にしか動かさない | |
| if (!isMousePressed) { | |
| return; | |
| } | |
| if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) { | |
| var mouseX = Input.GetAxis ("Mouse X"); | |
| var mouseY = Input.GetAxis ("Mouse Y"); | |
| var diffX = mouseX - oldMouseX; | |
| var diffY = mouseY - oldMouseY; | |
| this.transform.Rotate (new Vector3 (-diffY * speedY, diffX * speedX, 0)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment