The player in my 2d game has the ability to teleport to a checkpoint(the checkpoint can be wherever he wants, what im doing is that I created a prefab of the player so, the player is just an instance of that prefab
and, when the player presses E it destroys his gameobject and instanciates another one from the same prefab
if(canEgg == true && hasEgg == false)
{
Instantiate(eggPrefab, nuggetsPrefab.transform.position, nuggetsPrefab.transform.rotation);
canEgg = false;
hasEgg = true;
}
if (canEgg == true && hasEgg == true)
{
Destroy(gameObject);
canEgg = false;
hasEgg = false;
Instantiate(nuggetsPrefab, eggPrefab.transform.position, eggPrefab.transform.rotation);
}
Just for clarification, the player is a chicken, im in a 2d space, and the checkpoints are eggs, what I did there is that if the player presses E he creates a checkpoint, and if he presses E again he ““teleports”” to that checkpoint (dies and spawn another instance)
But when i play the game, the new player instance does not have activated the script or any components, just the sprite renderer(and the camera is a child of the player so it follows the player, but when the player is killed, it says there is no camera, even if the new player also has a maincamera child