unity follow player 2d code example
Example 1: how to make camera follow player unity 2d
public class CameraFollow : MonoBehaviour {
public GameObject Target;
private Vector3 Offset;
// Start is called before the first frame update
void Start() {
Offset = transform.position - Target.transform.position;
}
// Update is called once per frame
void Update() {
transform.position = Target.transform.position+Offset;
}
}
Example 2: unity look at 2d
transform.right = target.position - transform.position; // Works like a CHARM.