예제 #1
0
    public static void LoadPlayer(int levelIndex, GameObject[] cps)
    {
        GameObject       player           = GameObject.FindGameObjectWithTag("Player");
        PlayerController playerController = player.GetComponent <PlayerController>();

        int counter = 0;

        foreach (GameObject cp in cps)
        {
            if (cp.transform.position != Gamemanager.LastCheckpointPosition)
            {
                counter++;
            }
            else
            {
                continue;
            }

            if (counter == cps.Length)
            {
                Gamemanager.LastCheckpointPosition = cps[0].transform.position;
            }
        }

        if (Gamemanager.HighestLevel < levelIndex)
        {
            player.transform.position          = cps[0].transform.position;
            Gamemanager.PlayerHealth           = Gamemanager.PlayerMaxHealth;
            Gamemanager.LastCheckpointPosition = cps[0].transform.position;
            Gamemanager.SavePlayer(playerController, Gamemanager.LastLevel);
        }
        else if (Gamemanager.LastLevel == levelIndex && !Gamemanager.PlayerDead)
        {
            Gamemanager.LoadPlayer(levelIndex);
            player.transform.position = Gamemanager.SavedPlayerPositions[levelIndex];
            Gamemanager.PlayerHealth  = Gamemanager.PlayerMaxHealth;
            Gamemanager.SavePlayer(playerController, Gamemanager.LastLevel);
            Gamemanager.PlayerDead = false;
        }
        else if (Gamemanager.PlayerDead)
        {
            player.transform.position = Gamemanager.LastCheckpointPosition;
            Gamemanager.PlayerHealth  = Gamemanager.PlayerMaxHealth;
            Gamemanager.SavePlayer(playerController, Gamemanager.LastLevel);
            Gamemanager.PlayerDead = false;
        }
        else
        {
            Gamemanager.LoadPlayer(levelIndex);
            player.transform.position = Gamemanager.SavedPlayerPositions[levelIndex];
            PlayerController.Health   = Gamemanager.PlayerHealth;
        }
    }