Esempio n. 1
0
    private void Spawn(byte[] data, EndPoint sender)
    {
        uint   prefabType = BitConverter.ToUInt32(data, 1);
        uint   objectID   = BitConverter.ToUInt32(data, 5);
        uint   ClientID   = BitConverter.ToUInt32(data, 9);
        string teamTag    = "";

        if (MyIDonServer == ClientID)
        {
            teamTag = ClientTeamTag;
        }
        else if (MyIDonServer != ClientID)
        {
            teamTag = enemyTeamTag;
        }

        float x = BitConverter.ToSingle(data, 13);

        if (teamTag == "BlueTeam")
        {
            x = -x;
        }
        float y = BitConverter.ToSingle(data, 17);
        float z = BitConverter.ToSingle(data, 21);

        if (serverPrefabs.ContainsKey(prefabType))
        {
            GameObject newGameObject = Instantiate(serverPrefabs[prefabType]);

            Vector3 position = new Vector3(x, y, z);
            newGameObject.transform.position = position;
            spawnedGameObjects[objectID]     = newGameObject;

            //rotation
            Vector3 rotation = new Vector3(0, 90, 0);
            if (teamTag == "RedTeam")
            {
                rotation *= -1;
            }
            newGameObject.transform.rotation = Quaternion.Euler(rotation);
            BaseClass objectClass = newGameObject.GetComponent <BaseClass>();

            objectClass.SetID(objectID);

            objectClass.TeamTag = teamTag;
            newGameObject.GetComponent <CharacterStateMachine>().BSM = bsm;
            newGameObject.GetComponent <CharacterStateMachine>().SetServer(this);

            newGameObject.SetActive(true);
            newGameObject.name = newGameObject.GetComponent <BaseClass>().CharacterName;
            bsm.AddToTeamList(objectClass);
            Console.WriteLine("Spawned");
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        gameLogic.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Space) && !hasInstancite)
        {
            GameObject obj      = Instantiate(prefab, bTeam);
            BaseClass  objClass = obj.GetComponent <BaseClass>();
            objClass.TeamTag = "BlueTeam";
            obj.GetComponent <CharacterStateMachine>().BSM = bsm;
            obj.SetActive(true);

            bsm.AddToTeamList(objClass);

            bsm.ActiveUI();

            hasInstancite = true;
        }
    }