Exemplo n.º 1
0
 private void HandleSpawnObject(NetCommand.SpawnObject cmd)
 {
     // Only spawn the object if it wasn't created by us.
     // TODO: Instead we should attach to the live object.
     if (cmd.CreatorPlayerId != localPlayer.Id)
     {
         networkObjectManager.SpawnPlayerObject(
             cmd.NetworkObjectState.NetworkId,
             cmd.Type,
             cmd.Position,
             cmd.Orientation);
     }
     else if (cmd.WasAttackHit)
     {
         // Play a hit confirm sound for debugging purposes.
         hitConfirmSound.Play();
     }
 }
Exemplo n.º 2
0
    /**
     * IPlayerActionHandler interface.
     *
     * TODO - Consider breaking this into a delegate.
     */
    public void HandlePlayerAttack(
        Player player, NetworkObjectType type, Vector3 position, Quaternion orientation)
    {
        // Create the attack object and check for hits.
        var obj    = networkObjectManager.SpawnPlayerObject(0, type, position, orientation);
        var wasHit = simulation.ProcessPlayerAttack(player, obj.GetComponent <HitscanAttack>());

        // Broadcast to all players the spawned object data.
        var spawnObjectCmd = new NetCommand.SpawnObject {
            NetworkObjectState = obj.ToNetworkState(),
            Type            = type,
            CreatorPlayerId = player.Id,
            Position        = obj.transform.position,
            Orientation     = obj.transform.rotation,
            WasAttackHit    = wasHit,
        };

        netChannel.BroadcastCommand(spawnObjectCmd);
    }