Completed course 2 adn 3, working on 4
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting.APIUpdating;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public static CameraController instance;
|
||||
public float moveSpeed;
|
||||
public float zoomSpeed;
|
||||
public float rotateSpeed;
|
||||
public float minZoomDist;
|
||||
public float maxZoomDist;
|
||||
private Camera cam;
|
||||
void Awake()
|
||||
{
|
||||
cam = Camera.main;
|
||||
instance = this;
|
||||
}
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
@@ -24,8 +28,16 @@ public class CameraController : MonoBehaviour
|
||||
{
|
||||
Move();
|
||||
Zoom();
|
||||
Rotate();
|
||||
}
|
||||
|
||||
private void Rotate()
|
||||
{
|
||||
float leftInput = Input.GetKey(KeyCode.E) ? 1.0f : 0.0f;
|
||||
float rightInput = Input.GetKey(KeyCode.Q) ? 1.0f : 0.0f;
|
||||
float rotAmount = (rightInput - leftInput) * rotateSpeed * Time.deltaTime;
|
||||
transform.Rotate(Vector3.up, rotAmount);
|
||||
}
|
||||
private void Move()
|
||||
{
|
||||
float xInput = Input.GetAxisRaw("Horizontal");
|
||||
@@ -35,12 +47,12 @@ public class CameraController : MonoBehaviour
|
||||
}
|
||||
private void Zoom()
|
||||
{
|
||||
float scrollInput = Input.GetAxisRaw("Mouse ScrollWheel");
|
||||
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
||||
float dist = Vector3.Distance(transform.position, cam.transform.position);
|
||||
if(dist < minZoomDist && scrollInput > 0.0f)
|
||||
return;
|
||||
if(dist > maxZoomDist && scrollInput < 0.0f)
|
||||
return;
|
||||
return;
|
||||
else if(dist > maxZoomDist && scrollInput < 0.0f)
|
||||
return;
|
||||
cam.transform.position += cam.transform.forward * scrollInput * zoomSpeed;
|
||||
}
|
||||
public void FocusOnPosition(Vector3 pos)
|
||||
|
||||
Reference in New Issue
Block a user