예제 #1
0
    internal IEnumerator RespawnWithDelay(float delay = 0f, GameObject killedBy = null)
    {
        if (killedBy)
        {
            Debug.LogFormat("{0} (Team {1}) killed by {2} (Team {3}).", name, team, killedBy.name, killedBy.GetComponent <Entity>().team);
        }
        else
        {
            Debug.LogFormat("{0} (Team {1}) killed.", name, team);
        }

        alive = false;
        Deactivate();

        yield return(new WaitForSeconds(delay));

        Debug.LogFormat("Respawning {0} (Team {1}).", name, team);

        GameObject spawnPoint = SpawnPointManager.GetSpawnPoint(team);

        rb2D.position = spawnPoint.transform.position;
        rb2D.rotation = spawnPoint.transform.rotation.z;

        yield return(new WaitForFixedUpdate()); // keeps entity from 'warping' in one frame

        alive  = true;
        health = startHealth;
        Activate(Vector2.zero);
    }
예제 #2
0
    public void InitializePlayer(bool selectOnCreation = true)
    {
        if (doNotRemoveAssetsWithTag)
        {
            var player = GameObject.FindWithTag("Player");
            if (player != null)
            {
                playerInstance = player;
            }
        }

        if (playerInstance == null && gameData.PlayerPrefab != null)
        {
            playerInstance = Instantiate(gameData.PlayerPrefab);

            playerInstance.transform.position = SpawnPointManager.GetSpawnPoint(0).Position;
            playerInstance.transform.rotation = SpawnPointManager.GetSpawnPoint(0).Rotation;
        }


        //  Select Player on creation.
        if (selectOnCreation)
        {
            UnityEditor.Selection.activeGameObject = playerInstance;
        }
    }
예제 #3
0
    public void PawnRequest(ExamplePlayerController controller)
    {
        ExamplePawn newPawn = Instantiate(GameManager.instance.pawnPrefab, SpawnPointManager.GetSpawnPoint(), Quaternion.identity);

        newPawn.ownerPlayerControllerId = controller.playerControllerId;
        newPawn.PlayerName = (controller).userName;

        serverManager.SpawnWithClientAuthority(newPawn.gameObject, controller.Conn);
    }
 /// <summary>
 /// Starts the gamemode.
 /// </summary>
 /// <param name="character">The character the player selected.</param>
 /// <param name="currentStage">The current stage we are on.</param>
 /// <param name="stageCollection"></param>
 public virtual void StartGameMode(EntityDefinition character, StageDefinition currentStage,
                                   StageCollection stageCollection = null)
 {
     this.stageCollection = stageCollection;
     this.currentStage    = currentStage;
     playerCamera         = Instantiate(gameManager.gameVariables.playerCameraPrefab.gameObject,
                                        spawnPointManager.GetSpawnPoint().position, Quaternion.identity)
                            .GetComponent <PlayerCamera>();
     ActivateGamemode();
 }
예제 #5
0
    protected void OnPawnRequestMessage(TinyNetMessageReader netMsg)
    {
        netMsg.ReadMessage(shortMessage);

        ExamplePawn newPawn = Instantiate(GameManager.instance.pawnPrefab, SpawnPointManager.GetSpawnPoint(), Quaternion.identity);

        newPawn.ownerPlayerControllerId = shortMessage.value;
        newPawn.PlayerName = ((ExamplePlayerController)netMsg.tinyNetConn.GetFirstPlayerController()).userName;

        serverManager.SpawnWithClientAuthority(newPawn.gameObject, netMsg.tinyNetConn);
    }
예제 #6
0
    private void Cmd_SpawnCharacter()
    {
        spawnPoint = SpawnPointManager.GetSpawnPoint(playerTeam);

        if (playerTeam == TeamType.Attackers)
        {
            playerObject = Instantiate(attackerPlayerObject, spawnPoint.position, spawnPoint.rotation) as GameObject;
        }
        else if (playerTeam == TeamType.Defenders)
        {
            playerObject = Instantiate(defenderPlayerObject, spawnPoint.position, spawnPoint.rotation) as GameObject;
        }

        playerObject.name = playerName + "Character";
        playerObject.GetComponent <ICharacter>().OnTakenDamage += OnCharacterTakenDamage;

        GameManager.instance.Cmd_PlayerJoined(playerTeam);

        NetworkServer.SpawnWithClientAuthority(playerObject, gameObject);
    }