camera following without rotation,Camera following with out rotation

I have fllowed the instructions of another persons code but it did not work instead it makes my whole screen the colour of my background.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camerafollow : MonoBehaviour
{
public GameObject player;

public float cameraHeight = 20.0f;

void Update()
{
    Vector3 pos = player.transform.position;

    pos.z += cameraHeight;

    transform.position = pos;
}

},I have used a code from another question and it does not work the reasons being that when i press play the whole screen goes to the colour of the background.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camerafollow : MonoBehaviour
{
public GameObject player;

public float cameraHeight = 20.0f;

void Update()
{
    Vector3 pos = player.transform.position;

    pos.z += cameraHeight;

    transform.position = pos;
}

}

@stickyrino876543
If your project is in 2D, why don’t you try using Cinemachine with your camera? There is a field on the inspector called follow where you can attach the object you want to follow. You can also adjust many values and personalize the “feel” of your camera.