How do I re-instantiate an object after it is destroyed from the scene?

I have a game object with a script attached called “playerController”. My plan is to destroy this game object from another script and Instantiate it again after 3 seconds via IENumerator. I want the game object to be instantiated with the exact transform values it had during the start of the game.

The following code is from the other script that will destroy the game object with “playerController” attached and re-spawn it after 3 seconds.

public IENumerator Respawn()
{
     destroy(playerController.gameObject);
     yield return new WaitForSeconds (3.0f);

     //This is where I respawn the game object with playerController script attached

}

You’re going to want to create a prefab for your player controller and then add this variable to your spawning script

public GameObject PlayerPrefab;

In the editor, drag and drop the prefab on that variable.

Then in your Respawn method:

GameObject go = Instantiate(PlayerPrefab);
playerController = go.GetComponent<PlayerController>();