unity how to make camera follow player 2d only x code example
Example 1: how to make camera follow player unity 2d
public class CameraFollow : MonoBehaviour {
public GameObject Target;
private Vector3 Offset;
void Start() {
Offset = transform.position - Target.transform.position;
}
void Update() {
transform.position = Target.transform.position+Offset;
}
}
Example 2: how to make a camera follow an object in unity 2d
public Transform player; public Vector3 offset; void Update () { transform.position = new Vector3 (player.position.x + offset.x, player.position.y + offset.y, offset.z);