This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Game 1/Assets/Scripts/CameraController.cs

35 lines
670 B
C#
Raw Permalink Normal View History

2017-09-05 20:11:49 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour {
public GameObject player;
2017-09-05 20:15:43 -05:00
private Vector3 offset;
2017-09-05 20:11:49 -05:00
private Vector3 newPosition;
2017-09-05 20:15:43 -05:00
private float minX, maxX, minY, maxY;
2017-09-05 20:11:49 -05:00
void Start () {
2017-09-05 20:15:43 -05:00
offset = transform.position - player.transform.position;
2017-09-07 02:06:06 -05:00
minX = -2.0f;
maxX = 2.0f;
2017-09-05 20:15:43 -05:00
minY = 0.0f;
maxY = 18.0f;
2017-09-05 20:11:49 -05:00
}
void LateUpdate () {
newPosition = player.transform.position + offset;
2017-09-05 21:06:46 -05:00
transform.position = new Vector3
(
Mathf.Clamp (newPosition.x, minX, maxX),
//transform.position.x,
Mathf.Clamp (newPosition.y, minY, maxY),
transform.position.z
);
2017-09-05 20:11:49 -05:00
}
2017-09-05 21:06:46 -05:00
}