Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Basic networking setup for 1v1 game where only one player has a prefab

Discussion in 'Multiplayer' started by sirival, Jul 4, 2015.

  1. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    Hello,

    I'm trying to understand how to create a basic networking setup for a game that works like this:

    - Game is 1v1
    - One of the players is the host
    - Player 1 controls an FPS character. Player 2 needs to see the FPS character of Player 1.
    - Player 2 does not control an FPS character - he manages other stuff in the game (so no playerPrefab for Player 2).
    - Both players see the same level (so there can be an Online Scene for the NetworkManager).

    So how do I set this up, so that when a game is started and both players connect, Player 1 starts controlling his character, and Player 2 sees Player's 1 character ?

    I don't need details like how transform synchronization works just how to setup the Network Manager for this to work..

    Thanks
     
  2. Kristonitas

    Kristonitas

    Joined:
    Jan 16, 2013
    Posts:
    9
  3. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
  4. Kristonitas

    Kristonitas

    Joined:
    Jan 16, 2013
    Posts:
    9
    I thought you wanted the 1vs1 part to be automated, and in the automatic matchmaking atm has some issues.

    If you can manually decide who hosts and who joins, then it shouldn't concern you for now.
    http://wiki.unity3d.com/index.php/UNET#
    Watch the Unite video with tanks example if you have time. But basically You create a prefab that every player will have, for simple controls you can add the standard FPS controller. Then every prefab that is synced has to have NetworkId, and if you want to sync the transform, you add the NetworkTransform component and adjust it for your needs. Then on some empty GameObject add a network manager and putt the required prefabs in the fields and that should be about it. When I start working on gameplay in my own project, I can bring more specific details. I hope this helps.
     
  5. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    Hey,

    So yeah I understand the simple case, and that NetworkManager was probably made just for the simplest possible case... But that's not exactly what I'm trying to do. Only one player has a prefab - the other doesn't. Do you know how can I spawn the first player in both clients but not spawn anything for the second player?
     
  6. Kristonitas

    Kristonitas

    Joined:
    Jan 16, 2013
    Posts:
    9
    If you prevent the server from adding player prefabs, you can do it manually with ClientScene.AddPlayer(int for player num in the server[check docs])
     
  7. jaybdemented

    jaybdemented

    Joined:
    Sep 2, 2013
    Posts:
    112
    I'm still learning networking but maybe add some code to the prefab in the start like
    find prefab, if null then that's player.
    Else set the model for the prefab setactive to false. Set a bool is co player to true.
    Then in update if player then goto this function.
    if co player run this function.

    Sorry for no code. Typing on my phone at work.