Search Unity

Multiplayer question and advice request.

Discussion in 'Scripting' started by chitanblue, Aug 21, 2013.

  1. chitanblue

    chitanblue

    Joined:
    Mar 15, 2013
    Posts:
    8
    I've been working on a 2d platformer game in Unity which has the option for synchronous multiplayer.

    Both player 1 and player 2 will be playing on identical levels.

    I have completed the single player portion of the game and have to implement player 2 now.

    I made the entire Single Player level and all it's component a prefab, brought it in and placed it where I want.
    Which brings me to my question...

    Should I duplicate and alter all of the scripts and place them on the second player?
    Considering the second player might need modifications here and there to some scripts, and some of those changes may be unwanted for both players. For example, the controls. The controls for player 2 will be different from player 1.

    OR
    Should I implement a way of checking in my script?
    For example,
    Code (csharp):
    1.  
    2. if(gameObject.name == Player 2)
    3. {
    4. check player 2 controls
    5. }
    6. else
    7. {
    8. SP controls
    9. }
    10.  
    11.  
    Thanks
     
  2. SlyRipper

    SlyRipper

    Joined:
    Jun 19, 2012
    Posts:
    251
    I guess it will be easier and better to work with to have just 1 script for each stuff you wanna do. For example use 1 control script you'll attach to a player object and let that instantiate for each player with adjusted values. So you need to place something of a check for it, like if(Network.isServer) or something like you already posted. Maybe use a simple int value while 0 stands for player1 and 1 for player2, so you just need to check the int variable which player is currently controlling the instantiated object.