-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraFollower.cs
More file actions
40 lines (33 loc) · 1.01 KB
/
CameraFollower.cs
File metadata and controls
40 lines (33 loc) · 1.01 KB
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;
namespace UnityStandardAssets._2D
{
[RequireComponent(typeof(Platformer2DUserControl))]
public class CameraFollower : MonoBehaviour
{
Transform player;
float offsetX;
// Use this for initialization
void Start()
{
GameObject player_go = GameObject.FindGameObjectWithTag("Player");
if (player_go == null)
{
Debug.LogError("Couldnt find GameObject Named Player");
return;
}
player = player_go.transform;
offsetX =transform.position.x - player.position.x;
}
// Update is called once per frame
void Update()
{
if (player != null) {
Vector3 pos = transform.position;
pos.x = player.position.x + offsetX;
transform.position = pos;
}
}
}
}