IEnumerator Respawn(float cooldown)
    {
        yield return(new WaitForSeconds(cooldown));

        GameObject arturSceneManager = GameObject.FindGameObjectWithTag("SceneManager");

        ArturMetaInf metaInf      = arturSceneManager.GetComponent <ArturMetaInf>();
        LevelMetaInf levelMetaInf = transform.GetComponentInParent <LevelMetaInf>();

        Vector3 respawnPosition = levelMetaInf.respawnLocation;


        GameObject playerOne = GameObject.FindGameObjectWithTag("Player1");
        GameObject playerTwo = GameObject.FindGameObjectWithTag("Player2");

        playerOne.transform.parent = null;
        playerTwo.transform.parent = null;

        ArturPlayerOneController p1 = playerOne.GetComponent <ArturPlayerOneController>();
        ArturPlayerTwoController p2 = playerTwo.GetComponent <ArturPlayerTwoController>();

        p1.Respawn(respawnPosition + new Vector3(0, 3, 0));
        p2.Respawn(respawnPosition + new Vector3(2, 3, 0));


        metaInf.playerLives--;


        GameObject[] rooms = GameObject.FindGameObjectsWithTag("Room");

        foreach (GameObject g in rooms)
        {
            Vector3    instantiateAt = g.GetComponent <LevelMetaInf>().instantiatedAt;
            GameObject room          = Resources.Load <GameObject>("Rooms/" + ArturSceneManager.currentLevel + "/" + g.GetComponent <LevelMetaInf>().roomNumber);
            room.GetComponent <LevelMetaInf>().instantiatedAt  = instantiateAt;
            room.GetComponent <LevelMetaInf>().lastBlock       = g.GetComponent <LevelMetaInf>().lastBlock;
            room.GetComponent <LevelMetaInf>().respawnLocation = g.GetComponent <LevelMetaInf>().respawnLocation;

            Instantiate(room, instantiateAt, Quaternion.identity);
            Destroy(g);
        }
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
        foreach (GameObject enemy in enemies)
        {
            Destroy(enemy);
        }

        string         enemyPath         = "Prefabs/Main/Enemies/Enemy";
        List <Vector3> allEnemyPositions = GameObject.FindGameObjectWithTag("ProceduralGenerator").GetComponent <ArturProceduralGeneratorManagerScript>().allEnemyPositions;

        foreach (Vector3 enemyPos in allEnemyPositions)
        {
            GameObject enemy = Resources.Load <GameObject>(enemyPath);
            Instantiate(enemy, enemyPos, Quaternion.identity);
        }
    }
Exemple #2
0
    IEnumerator Respawn(float cooldown)
    {
        yield return(new WaitForSeconds(cooldown));

        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
        foreach (GameObject enemy in enemies)
        {
            Destroy(enemy);
        }
        GameObject playerOne = GameObject.FindGameObjectWithTag("Player1");
        GameObject playerTwo = GameObject.FindGameObjectWithTag("Player2");

        playerOne.transform.parent = null;
        playerTwo.transform.parent = null;

        ArturPlayerOneController p1 = playerOne.GetComponent <ArturPlayerOneController>();
        ArturPlayerTwoController p2 = playerTwo.GetComponent <ArturPlayerTwoController>();

        ArturBasePlayerController behind = p1;

        if (p2.transform.position.x < p1.transform.position.x)
        {
            behind = p2;
        }


        GameObject[] rooms        = GameObject.FindGameObjectsWithTag("Room");
        LevelMetaInf levelMetaInf = rooms[0].GetComponent <LevelMetaInf>();

        for (int i = 0; i < rooms.Length - 1; i++)
        {
            if (rooms[i].transform.position.x <behind.transform.position.x &&
                                               rooms[i + 1].transform.position.x> behind.transform.position.x)
            {
                levelMetaInf = rooms[i].GetComponent <LevelMetaInf>();
            }
        }
        Vector3 respawnPosition = levelMetaInf.respawnLocation;

        p1.Respawn(respawnPosition + new Vector3(0, 3, 0));
        p2.Respawn(respawnPosition + new Vector3(2, 3, 0));

        foreach (GameObject g in rooms)
        {
            Vector3    instantiateAt = g.GetComponent <LevelMetaInf>().instantiatedAt;
            GameObject room          = Resources.Load <GameObject>("Rooms/" + ArturSceneManager.currentLevel + "/" + g.GetComponent <LevelMetaInf>().roomNumber);
            room.GetComponent <LevelMetaInf>().instantiatedAt  = instantiateAt;
            room.GetComponent <LevelMetaInf>().lastBlock       = g.GetComponent <LevelMetaInf>().lastBlock;
            room.GetComponent <LevelMetaInf>().respawnLocation = g.GetComponent <LevelMetaInf>().respawnLocation;

            Instantiate(room, instantiateAt, Quaternion.identity);
            Destroy(g);
        }

        string         enemyPath         = "Prefabs/Main/Enemies/Enemy";
        List <Vector3> allEnemyPositions = GameObject.FindGameObjectWithTag("ProceduralGenerator").GetComponent <ArturProceduralGeneratorManagerScript>().allEnemyPositions;

        foreach (Vector3 enemyPos in allEnemyPositions)
        {
            GameObject enemy = Resources.Load <GameObject>(enemyPath);
            Instantiate(enemy, enemyPos, Quaternion.identity);
        }

        //GameObject.FindGameObjectWithTag("ScreenFader").GetComponent<Animator>().SetBool("fade_out_in", false);
    }