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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user