|
using UnityEngine; |
|
using System.Collections; |
|
|
|
public class CameraLook : MonoBehaviour { |
|
float minFov; |
|
float maxFov; |
|
float sensitivity; |
|
|
|
int boundary; // distance from edge scrolling starts |
|
int speed; |
|
|
|
private int screenWidth; |
|
private int screenHeight; |
|
|
|
// Use this for initialization |
|
void Start() |
|
{ |
|
minFov = 15f; |
|
maxFov = 90f; |
|
sensitivity = 50f; |
|
|
|
boundary = 50; |
|
speed = 20; |
|
screenWidth = Screen.width; |
|
screenHeight = Screen.height; |
|
} |
|
|
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
float fov = Camera.main.fieldOfView; |
|
fov -= Input.GetAxis("Mouse ScrollWheel") * sensitivity; |
|
fov = Mathf.Clamp(fov, minFov, maxFov); |
|
Camera.main.fieldOfView = fov; |
|
Vector3 position = transform.position; |
|
|
|
if (Input.mousePosition.x > screenWidth - boundary && Input.mousePosition.x < screenWidth) |
|
{ |
|
position.x += speed * Time.deltaTime; |
|
} |
|
|
|
if (Input.mousePosition.x < 0 + boundary && Input.mousePosition.x >= 0) |
|
{ |
|
position.x -= speed * Time.deltaTime; |
|
} |
|
|
|
if (Input.mousePosition.y > screenHeight - boundary && Input.mousePosition.y < screenHeight) |
|
{ |
|
position.z += speed * Time.deltaTime; |
|
} |
|
|
|
if (Input.mousePosition.y < 0 + boundary && Input.mousePosition.y >= 0) |
|
{ |
|
position.z -= speed * Time.deltaTime; |
|
} |
|
|
|
transform.position = position; |
|
} |
|
|
|
void OnGUI() |
|
{ |
|
GUI.Box(new Rect((Screen.width / 2) - 140, 5, 280, 25), "Mouse Position = " + Input.mousePosition); |
|
GUI.Box(new Rect((Screen.width / 2) - 70, Screen.height - 30, 140, 25), "Mouse X = " + Input.mousePosition.x); |
|
GUI.Box(new Rect(5, (Screen.height / 2) - 12, 140, 25), "Mouse Y = " + Input.mousePosition.y); |
|
} |
|
} |
|
|