Pong-Pong/Assets/Scripts/CameraController.cs
Gerard Gascón 16da8e4dde init
2025-04-24 17:09:22 +02:00

27 lines
721 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour{
[HideInInspector]
public Transform follow;
public Vector2 minCamPos, maxCamPos;
public float smoothTime;
private Vector2 velocity;
// Update is called once per frame
void FixedUpdate(){
float posX = Mathf.SmoothDamp(transform.position.x,
follow.transform.position.x, ref velocity.x, smoothTime);
float posY = Mathf.SmoothDamp(transform.position.y,
follow.transform.position.y, ref velocity.y, smoothTime);
transform.position = new Vector3(
Mathf.Clamp(posX, minCamPos.x, maxCamPos.x),
Mathf.Clamp(posY, minCamPos.y, maxCamPos.y),
transform.position.z);
}
}