Ejemplo n.º 1
0
    private void SpawnPlayer(string clientId, Vector3 spawnLocation, Quaternion headRotation, int playerTypeId, bool isMain)
    {
        GameObject newPlayer = null;
        Player     player    = null;

        switch (playerTypeId)
        {
        case 0:
            newPlayer = Instantiate(playerPrefab, spawnLocation, new Quaternion());
            Hider hider = newPlayer.AddComponent <Hider>();
            hider.Instantiate(clientId, networkManager, true, isMain);
            player = hider;
            break;

        case 1:
            newPlayer = Instantiate(seekerPrefab, spawnLocation, new Quaternion());
            Seeker seeker = newPlayer.AddComponent <Seeker>();
            seeker.Instantiate(clientId, networkManager, true, isMain);
            player = seeker;
            networkManager.seeker = seeker;
            break;
        }

        //Add the camera to this player
        if (player.IsMainPlayer)
        {
            camera.transform.parent        = newPlayer.GetComponent <LocalBodyObjects>().cameraHolder;
            camera.transform.localPosition = new Vector3(0, 0, 0);

            SmoothMouseLook mouseLook = camera.gameObject.AddComponent <SmoothMouseLook>();
            mouseLook.playerBody       = newPlayer.transform;
            mouseLook.localBodyObjects = newPlayer.GetComponent <LocalBodyObjects>();

            foreach (Transform child in newPlayer.GetComponentsInChildren <Transform>(true))
            {
                child.gameObject.layer = mainPlayerLayer;
            }
        }

        networkManager.AddOnlinePlayer(player);
    }