Camera System halb fertig, wurde in letzter Unterrichtsstunde gemacht.
This commit is contained in:
31
Assets/Scripts/Cameras/CameraLook.cs
Normal file
31
Assets/Scripts/Cameras/CameraLook.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraLook : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float cameraSensivity;
|
||||
[SerializeField] private float minLookDist;
|
||||
[SerializeField] private float maxLookDist;
|
||||
|
||||
Vector2 touchDeltaPosition;
|
||||
float camLookDist;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
camLookDist = transform.localRotation.y;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.touchCount > 0 &&
|
||||
Input.GetTouch(0).phase == TouchPhase.Moved) {
|
||||
|
||||
touchDeltaPosition = Input.GetTouch(0).deltaPosition;
|
||||
camLookDist = Mathf.Clamp(camLookDist + touchDeltaPosition.x * cameraSensivity, minLookDist, maxLookDist);
|
||||
transform.localRotation = Quaternion.Euler(0f, camLookDist, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Cameras/CameraLook.cs.meta
Normal file
2
Assets/Scripts/Cameras/CameraLook.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49abaa4b8268a754399fa82119a91c67
|
||||
73
Assets/Scripts/Cameras/CameraSystem.cs
Normal file
73
Assets/Scripts/Cameras/CameraSystem.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraSystem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject[] cams;
|
||||
[SerializeField] private GameObject mainCam;
|
||||
[SerializeField] private int currentCam;
|
||||
[SerializeField] private KeyCode openCam;
|
||||
[SerializeField] private bool camIsOpen;
|
||||
[SerializeField] private float cdTimer;
|
||||
[SerializeField] private float cdTime = 0.5f;
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
for (int i = 0; i < cams.Length; i++) {
|
||||
cams[i].SetActive(false);
|
||||
}
|
||||
mainCam.SetActive(true);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(openCam)) {
|
||||
camIsOpen = !camIsOpen;
|
||||
ShowCam();
|
||||
}
|
||||
|
||||
if (cdTimer <= 0) {
|
||||
if (Input.GetAxis("Horizontal") > 0) {
|
||||
cams[currentCam].SetActive(false);
|
||||
currentCam = currentCam + 1;
|
||||
if (currentCam >= cams.Length) {
|
||||
currentCam = 0;
|
||||
}
|
||||
Go2Cam(currentCam);
|
||||
cdTimer = cdTime;
|
||||
}
|
||||
else if (Input.GetAxis("Horizontal") < 0) {
|
||||
cams[currentCam].SetActive(false);
|
||||
currentCam = currentCam - 1;
|
||||
if (currentCam < 0) {
|
||||
currentCam = cams.Length - 1;
|
||||
}
|
||||
Go2Cam(currentCam);
|
||||
cdTimer = cdTime;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cdTimer -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowCam() {
|
||||
if (camIsOpen) {
|
||||
cams[currentCam].SetActive(true);
|
||||
mainCam.SetActive(false);
|
||||
}
|
||||
else {
|
||||
cams[currentCam].SetActive(false);
|
||||
mainCam.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Go2Cam(int progression) {
|
||||
cams[currentCam].SetActive(false);
|
||||
currentCam = progression;
|
||||
ShowCam();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Cameras/CameraSystem.cs.meta
Normal file
2
Assets/Scripts/Cameras/CameraSystem.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc016bf314b3fa446a75c1810d0e5df6
|
||||
Reference in New Issue
Block a user