protected void LateUpdate() { if (players.Count > 0) { Vector3 slowestPlayer = GetSlowestPlayerCoordinates(); Vector3 newCameraCoordinates; CameraConstraints updateConstraints = CameraUpdateConstraints; float xCamera = Mathf.Clamp(slowestPlayer.x, cameraConstraints.minX, cameraConstraints.maxX); float yCamera = transform.position.y; if (slowestPlayer.y > (updateConstraints.maxY / 2) || slowestPlayer.y < updateConstraints.minY) { yCamera = Mathf.Clamp(slowestPlayer.y, cameraConstraints.minY, cameraConstraints.maxY); } newCameraCoordinates = new Vector3(xCamera, yCamera, transform.position.z); transform.position = newCameraCoordinates; } }
public void SetCameraConstrains(float minX, float minY, float maxX, float maxY) { cameraConstraints = new CameraConstraints(minX, minY, maxX, maxY); }