You should use code tags , and you should be more explicit about what thing “doesn’t work”. Do you get an error message? If so, when? Does it refer to a specific line of code? Does anything at all happen in your game? Can you confirm that specific parts of your code are or aren’t running by adding Debug.Log calls?
Right, sorry let me try and be more explicit. I don’t get any errors with this code but here is an error i get when trying to reference the player in a respawn script on a different instantiated prefab.
UnassignedReferenceException: The variable player of respawn has not been assigned.
You probably need to assign the player variable of the respawn script in the inspector.
I guess my player manager script isnt working. Is there a different way to reference the player within a prefab?
That error means you are trying to use a variable that hasn’t been given a value. There are lots of possible reasons that your attempts to give it a value might have failed, but AFAICT you don’t seem to have shown the code that is actually getting the error OR the code that is supposed to assign the variable, which makes it pretty much impossible to guess what you did wrong.
Well, let me try and guess ))
I believe your should use more reliable method for referencing the player. This
player = Object.FindObjectOfType<player>();
actually enumerates all objects in your scene and checks every script on them if it is player script or not. And this will not work if player is initially disabled in the scene or spawned in another script start method.
You need to have something like
player = PlayerManager.currentPlayer;
where current player variable is set by manager or other script. With it, you may do things like this