-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraFollow.cs
40 lines (30 loc) · 948 Bytes
/
CameraFollow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public GameObject cameraTarget;
public GameObject player;
public float smoothTime = 0.1f;
public bool cameraFollowX = true;
public bool cameraFollowY = true;
public bool cameraFollowHeight = false;
public float cameraHeight = 2.5f;
public float xOffset = 1f;
public Vector2 velocity;
private Transform thisTransform;
// Use this for initialization
void Start () {
thisTransform = transform;
}
// Update is called once per frame
void Update () {
if (cameraFollowX) {
float newPosition = Mathf.SmoothDamp (thisTransform.position.x, cameraTarget.transform.position.x, ref velocity.x, smoothTime);
thisTransform.position = new Vector3(newPosition, thisTransform.position.y, thisTransform.position.z);
}
if (cameraFollowY) {
}
if (!cameraFollowY && cameraFollowHeight) {
}
}
}