Exemplo n.º 1
0
    //Clear data if not connected to a server or when you quit the game
    public void Clear()
    {
        Selected     = -1;
        Chosen       = false;
        _storeLoaded = false;
        // Reset the game mode sprites
        _gameMode = new GameObject[0];
        // Reset the score menu
        SharedScore.GetComponent <PlaceController>().Reset();
        SharedScore.SetActive(false);

        // Hide all the sprites
        IGS.SetActive(false);
        Countdown[0].SetActive(false);
        Countdown[1].SetActive(false);
        Countdown[2].SetActive(false);
        Wait.SetActive(false);
        Host.SetActive(false);
        Tab.SetActive(false);
        foreach (Transform child in Dots.transform)
        {
            child.gameObject.SetActive(false);
        }
        foreach (Transform t in Ability.GetComponentsInChildren <Transform>())
        {
            t.GetComponent <SpriteRenderer>().enabled = false;
        }
        // destroy the mode selectors. They will automatically delete themselves anyway but there is a delay
        GameObject[] modes = GameObject.FindGameObjectsWithTag("Mode");
        foreach (GameObject m in modes)
        {
            Destroy(m);
        }
        // Reset the dodgeball generators
        foreach (GameObject DBG in DBGS)
        {
            DBG.GetComponent <DBGenerator>().Counter = 0;
            DBG.GetComponent <DBGenerator>().InGame  = false;
        }

        // Destroy all the dodgeballs
        foreach (GameObject b in GameObject.FindGameObjectsWithTag("DodgeBall"))
        {
            Destroy(b);
        }
        // Destroy all the players in a single player game. Automatically done
        // in online games
        if (SinglePlayer)
        {
            foreach (GameObject p in GameObject.FindGameObjectsWithTag("Player"))
            {
                Destroy(p);
            }
        }

        // Reset variables
        SinglePlayer = false;
        _running     = false;
        Started      = false;
        StartCounter = -1;

        // Go to the home page
        GetComponent <TitleScreenController>().Home();

        // Reset the network controller
        if (_networkController.Client && !_networkController.Server)
        {
            _networkController.Client  = false;
            _networkController.Server  = false;
            _networkController.Players = 0;
            _networkManager.StopClient();
        }

        // If you are the server host tell all the clients to disconnect
        if (_networkController.Server)
        {
            NetController.GetComponent <NetworkController>().RpcDisconnect(GameObject.FindGameObjectsWithTag("Player").Length);
        }

        // Hide all end screen sprites
        GetComponent <WinnerScreen>().Clear();
    }
Exemplo n.º 2
0
    //Reset between games
    public void GameOver()
    {
        // Reset the dodgeball generators
        foreach (GameObject DBG in DBGS)
        {
            DBG.GetComponent <DBGenerator>().Counter = 0;
            DBG.GetComponent <DBGenerator>().InGame  = false;
        }
        Selected = -1;
        Chosen   = false;
        if (_gameMode.Length > 0)
        {
            _gameMode[0].GetComponent <ButtonController>().On = false;
            _gameMode[1].GetComponent <ButtonController>().On = false;
        }
        _storeLoaded = false;
        // Show lobby sprites and reset variables
        StartCounter = -1;
        _running     = false;
        Started      = false;
        Countdown[0].SetActive(true);
        Countdown[1].SetActive(true);
        Countdown[2].SetActive(true);
        if (SinglePlayer)
        {
            Tab.SetActive(true);
        }
        else
        {
            foreach (GameObject m in _gameMode)
            {
                m.SetActive(true);
            }
            foreach (Transform child in Dots.transform)
            {
                child.gameObject.SetActive(true);
            }
            if (_networkController.Server)
            {
                Tab.SetActive(true);
            }
            else
            {
                Wait.SetActive(true);
                Host.SetActive(true);
            }
        }
        // Hide the score menu
        SharedScore.SetActive(false);
        // Destroy all the dodgeballs
        GameObject[] balls = GameObject.FindGameObjectsWithTag("DodgeBall");
        foreach (GameObject b in balls)
        {
            Destroy(b);
        }
        // Set all players scores to 0
        foreach (GameObject p in Players)
        {
            p.GetComponent <PlayerController>().ScoreDisplay.GetComponent <PlaceController>().Score = 0;
        }
        // Reset the score menu
        SharedScore.GetComponent <PlaceController>().Reset();
        SharedScore.SetActive(false);

        // Clear the end game screen
        GetComponent <WinnerScreen>().Clear();
    }