-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mouse control added: rotate cam, zoom in/out, WASD
- Loading branch information
1 parent
421c522
commit 463cf0b
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class MouseLookAround : MonoBehaviour | ||
{ | ||
// // Start is called before the first frame update | ||
// void Start() | ||
// { | ||
|
||
// } | ||
float rotationX = 0f; | ||
float rotationY = 0f; | ||
public float sensitivity = 2f; | ||
float moveSpeed = 10f; | ||
|
||
public Camera cam; | ||
// Update is called once per frame | ||
void Update() | ||
{ | ||
rotationY += Input.GetAxis("Mouse X") * sensitivity; | ||
rotationX += Input.GetAxis("Mouse Y") * -1 * sensitivity; | ||
transform.localEulerAngles = new Vector3(rotationX,rotationY,0); | ||
|
||
// WASD/Arrows: move cam | ||
transform.position += transform.forward * moveSpeed * Input.GetAxisRaw("Vertical") * Time.deltaTime; | ||
transform.position += transform.right * moveSpeed * Input.GetAxisRaw("Horizontal") * Time.deltaTime; | ||
|
||
// Zoom out Camera with Mouse Scroll Wheel | ||
if (Input.GetAxis("Mouse ScrollWheel") < 0) | ||
{ | ||
if (cam.fieldOfView <= 100) | ||
cam.fieldOfView += 2; | ||
if (cam.orthographicSize <= 20) | ||
cam.orthographicSize += 0.5F; | ||
} | ||
// Zoom in | ||
if (Input.GetAxis("Mouse ScrollWheel") > 0) | ||
{ | ||
if (cam.fieldOfView > 2) | ||
cam.fieldOfView -= 2; | ||
if (cam.orthographicSize >= 1) | ||
cam.orthographicSize -= 0.5F; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|