Simple Camera Follow

Hello there!

I am new to Unity. Have experience with game programming in C++ and SDL. I am aware of the entity-component system.

My question is regarding a simple camera follow.

Why is this code not working:

using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour
{
	public GameObject target;
	
	void Start()
	{

	}

	void Update() 
	{
		transform.position = new Vector3 (target.transform.position.x, target.transform.position.y, transform.position.z);
	}
}

But this one is:

using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour
{
	public Transform player;
	
	void Start()
	{

	}

	void Update() 
	{
		transform.position = new Vector3 (player.position.x, player.position.y, transform.position.z);
	}
}

Are you using it in 2d and attaching the script on the (orthographic) camera?

Yes I have attached the script to the camera and it is orthographic.

Can nobody explain me why this is not working? Am I missing something obvious?
I did realize that it does not only affect this situation, but in general every time I use “public GameObject target” and link it then in the Inspector it won’t get the target informations.