How to respawn player game object after game over

Hi,

I am trying to respawn the player after pressing the continue button and hiding the game over screen. Here is the code so far.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class UnitManager : MonoBehaviour
{
    public PlayerController ball;

    public float respawnDelay = 5;

    public GameObject currentCheckpoint;

    public GameStatus gs;

    private CountdownTimer ct;

    public GameObject destroyParticle;

    public GameObject respawnParticle;

    private float gravityStore;

    private HealthManager hm;

    public LivesSystem ls;

    public CameraController cam;

    public Reset res;

    public GameObject gameOver;

    void Start()
    {
        ball = FindObjectOfType<PlayerController>();
        gs = FindObjectOfType<GameStatus>();
        ct = FindObjectOfType<CountdownTimer>();
        hm = FindObjectOfType<HealthManager>();
        ls = FindObjectOfType<LivesSystem>();
        cam = FindObjectOfType<CameraController>();
        res = FindObjectOfType<Reset>();
    }

    public void RespawnPlayer()
    {
        hm.DestroyPlayer();
        if (gs.lives >= 2)
        {
            StartCoroutine("RespawnPlayerCo");
        }
        else
        {
            Over();
        }
    }

    public void Over()
    {
        StartCoroutine("OverCo");
    }

    public IEnumerator RespawnPlayerCo()
    {
        Instantiate(destroyParticle, ball.transform.position, ball.transform.rotation);
        ball.enabled = false;
        ball.GetComponent<Renderer>().enabled = false;
        cam.isFollowing = false;
        //gravityStore = ball.GetComponent<Rigidbody2D>().gravityScale;
        //ball.GetComponent<Rigidbody2D>().gravityScale = 0f;
        //ball.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
        Debug.Log("Player Respawned: " + transform.position);
        yield return new WaitForSeconds(respawnDelay);
        //ball.GetComponent<Rigidbody2D>().gravityScale = gravityStore;
        ball.transform.position = currentCheckpoint.transform.position;
        ball.enabled = true;
        ball.GetComponent<Renderer>().enabled = true;
        hm.Revive();
        cam.isFollowing = true;
        Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
    }

    public IEnumerator OverCo()
    {
        Instantiate(destroyParticle, ball.transform.position, ball.transform.rotation);
        cam.isFollowing = false;
        ball.GetComponent<Renderer>().enabled = false;
        //gravityStore = ball.GetComponent<Rigidbody2D>().gravityScale;
        //ball.GetComponent<Rigidbody2D>().gravityScale = 0f;
        //ball.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
        yield return new WaitForSecondsRealtime(3);
        gameOver.gameObject.SetActive(true);
    }

    public void DoOver()
    {
        StartCoroutine("Again");
    }

    public IEnumerator Again()
    {
        gameOver.gameObject.SetActive(false);
        Debug.Log("Player Respawned: " + transform.position);
        yield return new WaitForSeconds(1);
        //ball.GetComponent<Rigidbody2D>().gravityScale = gravityStore;
        ball.transform.position = currentCheckpoint.transform.position;
        ball.enabled = true;
        ball.GetComponent<Renderer>().enabled = true;
        hm.Revive();
        cam.isFollowing = true;
        Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
    }

    public void StartOver()
    {
        SceneManager.LoadScene("Intro");
    }
}

Any assistance would be appreciated.

Sincerely,

burchland2

Make the player a prefab, then Instantiate the prefab. I can see that you’ve already used Instantiate a bunch, so you probably won’t have trouble doing that.

I tried:

Instantiate(ball);
Instantiate(player); I assigned the player to both the ball and player variables. (I already made the player a prefab.
Instantiate(ball, ball.transform.position, ball.transform.rotation);
Instantiate(player, ball.transform.position, ball.transform.rotation);
The latter was a small mistake on my part.
But the same thing occurred with no player popping up. What else should I try? Is there something that I’m missing? Thank you.

Sincerely,

burchland2