-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraComponent.cs
More file actions
34 lines (30 loc) · 790 Bytes
/
Copy pathCameraComponent.cs
File metadata and controls
34 lines (30 loc) · 790 Bytes
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
using UnityEngine;
using System.Collections;
public class CameraComponent : MonoBehaviour
{
public GameObject cameraTarget;
// centers the camera at the camera target at startup
public bool startCentered;
// follows the camera target
public bool followTarget;
// Use this for initialization
void Start ()
{
if (startCentered)
{
Debug.Assert(cameraTarget);
Vector3 targetPos = cameraTarget.transform.position;
transform.position = new Vector3(targetPos.x, targetPos.y, transform.position.z);
}
}
// Update is called once per frame
void Update ()
{
if (followTarget)
{
Debug.Assert(cameraTarget);
Vector3 targetPos = cameraTarget.transform.position;
transform.position = new Vector3(targetPos.x, targetPos.y, transform.position.z);
}
}
}