I am having a weird issue with unity
When I reopen the scene the code finds my player object but not the script component
I fix this by removing the Player Object and just dragging a new player object to the scene.
But if I close the scene and reopen the scene again I have to redo the process again.
The code below is not attach to the player object, it is attached to multiple object as this is how I locate the player on the scene for instantiated objects
void Start() {
//DontDestroyOnLoad(transform.gameObject);
player = GameObject.FindGameObjectWithTag("Player");
if (player == null)
{
Debug.Log("PLAYER NOT FOUND");
}
else {
Debug.Log("PLAYER FOUND");
}
ps = player.gameObject.GetComponent<PlayerStat>();
if (ps == null)
{
Debug.Log("PS NOT FOUND");
}
}