Search Unity

Tanks!!! Reference Project, for Unity Multiplayer Q&A

Discussion in 'Community Learning & Teaching' started by richard-lee, Feb 17, 2017.

  1. JOSEPMP

    JOSEPMP

    Joined:
    Jan 25, 2019
    Posts:
    4


    I am having exactly the same problem, everything works properly (customize, single player, lobby room) except when I want to play a multiplayer mode. I get a green screen (waiting mode) until infinity plus many warnings messages on console, Do you have any practical solution?

    It is funny because in the editor window I see my online tanks moving around but green screen never disappears
     
  2. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    293
    @JOSEPMP What exactly are the warning messages? I opened this project in Unity 2019.1.1f1 and setup Android according to the official instructions and it worked just fine. However, I had to remove the Everyplay plugin completely to get it to successfully build. This is something you should do regardless because support for Everyplay has been discontinued. So if you still have this plugin in the project it may be causing issues since it's supposed to run at the start of each game.

    cc: @omnedeus_unity
     
  3. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    293
    Not familiar with AdMob but you can use the AddCurrency() method found in the PlayerDataManager script to modify the value. So try adding this to the end of your reward method:

    Code (CSharp):
    1. PlayerDataManager.s_Instance.AddCurrency(amount);
     
  4. kumarjamil

    kumarjamil

    Joined:
    Apr 1, 2019
    Posts:
    4
    yes it works but after leaving the game and returning to playing the score is reset to zero why is that?
     
    Last edited: May 16, 2019
  5. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    293
    Impossible to know without more info but what do you mean by "leaving the game"? You mean ending the match or just walking away for a bit? The score should actually be reset between matches but maybe you mean coins gained? If it's the latter case then you need to find out what's resetting your DataStore currency value.
     
  6. kumarjamil

    kumarjamil

    Joined:
    Apr 1, 2019
    Posts:
    4
    I mean, I turned off the game after getting a coin from AdMob (10 coins) and after I returned to the game and checked the score and the medal returned to zero. Coins can still be saved if they come from after completing the level (single player) but will return zero if obtained from AdMob. It looks like the coins from Admob cannot be saved.
     
  7. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    293
    The AddCurrency() method automatically saves the new value so I'm not sure how that's possible.

    I tested adding currency during a single-player mission with my cheats script and it worked just fine. So I can only guess that you must be resetting the currency value somewhere or calling the AdMob function at the wrong time.
     
  8. kumarjamil

    kumarjamil

    Joined:
    Apr 1, 2019
    Posts:
    4
    Actually this is because I tested it with the old AdMob plugin and after updating it didn't happen again. Case is closed. :D
     
  9. JOSEPMP

    JOSEPMP

    Joined:
    Jan 25, 2019
    Posts:
    4
    @IsaiahKelly This is the message I get:

    -
    Exception in OnStartClient:Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00029] in <ac823e2bb42b41bda67924a45a0173c3>:0
    at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <ac823e2bb42b41bda67924a45a0173c3>:0
    at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <ac823e2bb42b41bda67924a45a0173c3>:0
    at Tanks.Networking.NetworkManager.GetPlayerById (System.Int32 id) [0x00001] in /Users/admin/Desktop/New Unity Project/Assets/Scripts/Managers/NetworkManager.cs:531
    at Tanks.TankControllers.TankManager.Initialize () [0x00001] in /Users/admin/Desktop/New Unity Project/Assets/Scripts/Managers/TankManager.cs:184
    at Tanks.TankControllers.TankManager.OnStartClient () [0x00024] in /Users/admin/Desktop/New Unity Project/Assets/Scripts/Managers/TankManager.cs:177
    at UnityEngine.Networking.NetworkIdentity.OnStartClient () [0x0008d] in /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:364
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
     
  10. JOSEPMP

    JOSEPMP

    Joined:
    Jan 25, 2019
    Posts:
    4

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
    System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
    Tanks.Networking.NetworkManager.GetPlayerById (System.Int32 id) (at Assets/Scripts/Managers/NetworkManager.cs:531)
    Tanks.TankControllers.TankManager.Initialize () (at Assets/Scripts/Managers/TankManager.cs:184)
    Tanks.TankControllers.TankManager.OnPlayerIdChanged (System.Int32 playerId) (at Assets/Scripts/Managers/TankManager.cs:421)
    Tanks.TankControllers.TankManager.OnDeserialize (UnityEngine.Networking.NetworkReader reader, System.Boolean initialState) (at <2056e4b307474bc6b12f0cc8a568e1d6>:0)
    UnityEngine.Networking.NetworkIdentity.OnUpdateVars (UnityEngine.Networking.NetworkReader reader, System.Boolean initialState, UnityEngine.Networking.NetworkMessage netMsg) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:745)
    UnityEngine.Networking.ClientScene.OnUpdateVarsMessage (UnityEngine.Networking.NetworkMessage netMsg) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:729)
    UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, System.Int32 receivedSize, System.Int32 channelId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:469)
    UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, System.Int32 receivedSize, System.Int32 channelId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:425)
    UnityEngine.Networking.NetworkConnection.TransportReceive (System.Byte[] bytes, System.Int32 numBytes, System.Int32 channelId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:576)
    UnityEngine.Networking.NetworkClient.Update () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:754)
    UnityEngine.Networking.NetworkClient.UpdateClients () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:966)
    UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1086)
     
  11. JOSEPMP

    JOSEPMP

    Joined:
    Jan 25, 2019
    Posts:
    4
    Btw, Does someone know how to set up 2 Players game? I read the README DOC see below:

    This is the training day project Tanks ported to use the new Unity Multiplayer

    It use a slightly modified version of the StandardAsset Lobby.
    See StandardAssets/Network folder for more information on it.

    Input
    =====

    Keyboard Mapping
    ----------------
    Player 1:
    Forward = W
    Backward = S
    Rotate Left = A
    Rotate Right = D
    Fire = Space

    Player 2 :
    Directional Arrow to move & turn
    Keypad Enter to fire

    Pad (Xbox 360/One pad)
    ----------------------
    Forward = right trigger
    Backward = left trigger
    Fire = A
    Rotation = left/right on left stick

    In Lobby
    --------
    Pressing Forward will cycle colors
    Pressing Fire will get the player ready

    Pressing Fire for the second player will add it to the lobby (allowing to do a
    2 on one machine against two on another or 2-1-1)

    Matchmaker
    ==========
    To use the mathcmaker, you will need to create a project on your Unity Services
    account (see "Windows->Unity Services" in the editor)

    Misc. Notes
    ===========
    The modification to the standard asset lobby are mainly graphical, but there is
    one code modification : in LobbyPlayer, we added a check for "Fire2" to add a
    second player locally, allowing 2 player on the same machine

    In Lobby Does it work for you?