HELP! UnassignedReferenceException: The variable player of PlayerFollow has not been assigned.

I am trying to make the camera follow the player, but it doesnt works. I have this error: UnassignedReferenceException: The variable player of PlayerFollow has not been assigned.
(actually I have already assigned the variable in the inspector wtf)

using UnityEngine;

public class PlayerFollow : MonoBehaviour {



    public Transform player;
 

    // Update is called once per frame
    void Update () {

        transform.position = player.position;


    }
}

Help pls !!!

You have nothing assigned to player. Either you have to assign it by code, or you drag and drop the player into the player variable slot in the inspector.

4 Likes

Select your camera, then find the playerfollow script and drag the player from the hierarchy onto it.

5 Likes

THANKS!!!

You’re welcome.

help please it still cant fix the problem @fire7side

Start your own post instead of trying to hijack an over 2 year old post and create a meaningful help request post.

where is the playerfollow script

can you tell me how i can do that? MY discord username is Mistaken#1451

What is the code I would assign?

I’m going to close this thread, it’s just a necro magnet with no useful information being provided to the wider community.

2 Likes