Exemplo n.º 1
0
        // Use this for initialization
        void Start()
        {
            // if don't exist an instance of this class
            if (instance == null)
            {
                //it doesn't destroy the object, if other scene be loaded
                DontDestroyOnLoad(this.gameObject);

                instance = this;                // define the class as a static variable

                udpClient = gameObject.GetComponent <UDPClientComponent>();
            }
            else
            {
                //it destroys the class if already other class exists
                Destroy(this.gameObject);
            }
        }
Exemplo n.º 2
0
    //setup player position as instanciated
    void setPlace()
    {
        GameObject networkManager = GameObject.Find("NetworkManager");

        //finding parent (canvas) and position to where this player should be.
        GameObject parent = GameObject.Find("Canvas");

        transform.SetParent(parent.transform);


        //finding all spawn points
        for (int pPos = 0; pPos < 4; pPos++)
        {
            playerPos[pPos] = GameObject.Find("PlayerPos" + pPos.ToString()).transform;
        }

        //now finding all players in game
        UDPServerModule.UDPServer server = networkManager.GetComponent <UDPServer>();
        int joinedPlayers = server.connectedClients.Count;

        int playerPosNo = 0;

        switch (joinedPlayers)
        {
        case 1:
            playerPosNo = 0;
            break;


        case 2:
            playerPosNo = 3;
            break;


        case 3:
            playerPosNo = 2;
            break;


        case 4:
            playerPosNo = 1;
            break;
        }

        List <string> keys = new List <string>(server.connectedClients.Keys);



        foreach (string key in keys)
        {
            //Debug.Log(server.connectedClients[key].id);

            crntPlayer = GameObject.Find(server.connectedClients[key].id);

            //crntPlayer.transform.position = playerPos[playerPosNo].position;

            Debug.Log(crntPlayer.name);

            playerPosNo++;
        }
    }