Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save peroon/a991b3f78f8e02cd384c to your computer and use it in GitHub Desktop.

Select an option

Save peroon/a991b3f78f8e02cd384c to your computer and use it in GitHub Desktop.
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