Beispiel #1
0
    public override IEnumerator SlowUpdate()
    {
        lava = GameObject.FindObjectOfType <Lava>();
        if (IsClient)
        {
            //Hide Connection Page from clients
            GameObject.FindGameObjectWithTag("NetworkManager").transform.GetChild(0).GetComponent <Canvas>().gameObject.SetActive(false);
        }

        while (!GameReady && IsClient)
        {
            //Client shouldn't do anything until the game starts
            yield return(new WaitForSeconds(.2f));
        }

        if (IsServer)
        {
            while (!GameReady)
            {
                //See if all the players are ready
                //If not, wait
                bool testReady = true;

                MyPlayers = GameObject.FindObjectsOfType <NetworkPlayer>();
                if (MyPlayers.Length > 1 && (redPlayers != 0 || greenPlayers != 0))
                {
                    foreach (NetworkPlayer c in MyPlayers)
                    {
                        if (!c.canStart)
                        {
                            testReady = false;
                            break;
                        }
                    }

                    if (testReady)
                    {
                        GameReady = true;
                        //Send Game Start
                    }
                    yield return(new WaitForSeconds(.2f));
                }


                yield return(new WaitForSeconds(.2f));
            }
            SendUpdate("GAMESTART", "1");

            MyCore.NotifyGameStart();



            //Tell the clients to activate a temporary splash screen on the Network Manager canvas.
            //Spawn the objects

            MyPlayers = GameObject.FindObjectsOfType <NetworkPlayer>();
            NetworkPlayerController[] MyControllers = GameObject.FindObjectsOfType <NetworkPlayerController>();

            int i = 0;
            int j = 0;
            foreach (NetworkPlayer c in MyPlayers)
            {
                foreach (NetworkPlayerController p in MyControllers)
                {
                    if (c.Owner == p.Owner)
                    {
                        c.KillPlayer(p);
                        break;
                    }
                }

                //Spawning when player connects
                //GameObject temp = MyCore.NetCreateObject(c.ModelNum+1, c.Owner, new Vector3(-18 + ((c.Owner * 3)), 88, -112));

                //Send them to the correct spawn locations


                //temp.GetComponent<NetworkPlayerController>().SendUpdate("COLOR", c.ColorType);
                //temp.GetComponent<NetworkPlayerController>().SendUpdate("PNAME", c.PNAME);

                //if class == "fighter"
                //temp.GetComponent<NetworkPlayer>().SendUpdate("SETHP", "100");
            }


            while (!GameEnd)
            {
                yield return(new WaitForSeconds(1f));
            }

            SendUpdate("GAMEEND", "1");
            StartCoroutine(KillGame());

            while (true)
            {
                yield return(new WaitForSeconds(10));
            }
            Debug.Log("The Game Is Over!");
            yield return(new WaitForSeconds(20));
            //MyCore.LeaveGame();
            //Wait for 25 seconds
            //Leave Game.
            //MyCore.LeaveGame();
        }
    }