Beispiel #1
0
    void Update()
    {
        if (Network.isServer)
        {
            //Every X frames
            if (Time.frameCount % 15 == 0)
            {
                //pick a random wall
                int r = rng.Next() % mazeSize;
                int c = rng.Next() % mazeSize;

                //get the wallscript
                WallScript ws     = WallArray[r][c].GetComponent <WallScript>();
                float      height = ws.GetHeight();

                if (height == 1.0f)
                {
                    ws.SetHeight(0.0f);
                    //Debug.Log("raising wall at row " + r + ", col "+c);
                }
                else if (height == 0.0f)
                {
                    ws.SetHeight(1.0f);
                    //Debug.Log("lowering wall at row " + r + ", col "+c);
                }

                networkView.RPC("moveWall", RPCMode.Others, r, c, (int)ws.GetHeight());
            }
        }
    }
Beispiel #2
0
    void SendDataToPlayers()
    {
        string dataToSend = "";

        foreach (GameObject[] GOarray in WallArray)
        {
            foreach (GameObject GO in GOarray)
            {
                WallScript ws = GO.GetComponent <WallScript>();
                int        r  = ws.getRow();
                int        c  = ws.getCol();
                dataToSend += r + "," + c + "," + ws.GetHeight() + "|";
            }

            dataToSend = dataToSend.Substring(0, dataToSend.Length - 1);
            //Debug.Log("Sending data: "+ dataToSend);
            networkView.RPC("setMaze", RPCMode.Others, dataToSend);
            dataToSend = "";

            //Had to send the data at the end of every Row, turns out
            //that 4080 something characters was the maximum string allowed
            //to be sent through RPC calls.
        }

        networkView.RPC("setMaze", RPCMode.Others, "DONE");
    }
Beispiel #3
0
    int[] findOpenSpaceNear(int x, int z)
    {
        while (true)
        {
            //try to find open space.
            WallScript ws = WallArray[x][z].GetComponent <WallScript>();
            if (ws.GetHeight() == 1 && ws.getLockState() == false)
            {
                //this X and Y location is good. Break.
                Debug.Log("Found open space at x:" + x + ", z:" + z);
                break;
            }

            //This space isn't open, get one nearby then loop.
            else
            {
                //Get random new location nearby.
                int dir = rng.Next() % 4;
                switch (dir)
                {
                case 0: x++; break;

                case 1: x--; break;

                case 2: z++; break;

                case 3: z--; break;
                }

                //make sure we don't go OOB.
                if (x > mazeSize)
                {
                    x--;
                }
                else if (x < 0)
                {
                    x++;
                }
                if (z > mazeSize)
                {
                    z--;
                }
                else if (z < 0)
                {
                    z++;
                }
            }
        }
        return(new int[2] {
            x, z
        });
    }