Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

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

  1. AlecLarsen1989

    AlecLarsen1989

    Joined:
    Feb 7, 2017
    Posts:
    18
    Hi LLRx

    As mentioned previously, Tanks!!! was not built with localisation in mind. But let me help you with the last batches of translations :). For shooting range UI and Settings UI, edit the following prefabs under UI:
    * ShootingRangeModal
    * ShootingRangeStartGameModal
    * Settings

    For the buttons in the ServerList and Lobby this text is changed in code. The easiest way to change this is to search the entire solution for the string literals and change them. I hope this helps :)
     
  2. AlecLarsen1989

    AlecLarsen1989

    Joined:
    Feb 7, 2017
    Posts:
    18
    Hi fnaveedshah

    I tested out the method I sent you and I am not seeing that issue. If you could send me the full editor log (console) then I'd be happy to look at it for you :)
     
  3. AlecLarsen1989

    AlecLarsen1989

    Joined:
    Feb 7, 2017
    Posts:
    18
    Hi iTzRixerGG

    Please refer to my response to @fnaveedshah where I describe this process :).
     
  4. AlecLarsen1989

    AlecLarsen1989

    Joined:
    Feb 7, 2017
    Posts:
    18
    Hi alexdion

    We have solved this issue in the Tanks!!! project, given in the first post on this forum :). The above code looks like an excerpt from the old Tanks networking project. The delay you are seeing is network delay (ping). It's basically there because the server is creating the projectile and causing the client to do the same. Check out our solution in the new Tanks!!! project :)
     
  5. miterrooter

    miterrooter

    Joined:
    Oct 4, 2016
    Posts:
    3
    Sorry about bumping my own post up I just wanted to add these tags for @richard-lee & @AlecLarsen1989 . I am not too familiar to posting in the forums so im not sure if this is necessary. I think my question is best targeted at you two so if you could find the time to explain how to get to a solution(or if im going in the entirely wrong direction) I would greatly appreciate the help. Alternatively the document mentioned in previous posts seems like it would be a great guide.
     
  6. richard-lee

    richard-lee

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    50
    My mistake all. The package will be updated with the document. For now, it is attached to this post.
     

    Attached Files:

  7. miterrooter

    miterrooter

    Joined:
    Oct 4, 2016
    Posts:
    3
    Thanks @richard-lee the document is a good introduction of how the code is structured. It helps before going to reverse engineer the code. I have still run into difficulty if anyone can help. I have decided to try to add a local host feature for testing reasons. What I am trying is to add a button to the create game panel and from that button create a local host lobby. This has only worked so far as to create a lobby entry for the player but the ready button is not enabled. I would just like to know am i going about this the right way and if there are any tips to solve this.
     
  8. eDorosh

    eDorosh

    Joined:
    Aug 20, 2016
    Posts:
    1
    Hi. I'm developing my own project with UNet (4 person multiplayer) and have one very nasty issue with collapsing app on host (on mobile). I downloaded "Tanks!!!" to learn it, and found thing that :
    - If I get and run build that downloaded from AppStore, play it, and the host collapse his app -> it (host) has at least 2-3 seconds to maximize app and save current match without "server disconnected";
    - however If I create my own build of Tanks!!! (I change nothing, only make build), run it on mobile and host is collapsing -> other participants get "server disconnected" immediately!
    Why?
     
  9. richard-lee

    richard-lee

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    50
    eDorosh. Couple of scenarios come to mind.

    - Difference in version. The version on the app store was built on, if I recall correctly, 5.4.
    - Didn't setup Multiplayer. You said you didn't make any changes to the app. At minimum, if you're taking the project and build locally, so you setup your Multiplayer settings. This is in the documentation (Section 2.1)
     
  10. fnaveedshah

    fnaveedshah

    Joined:
    Dec 15, 2013
    Posts:
    6
    Sir ty for looking at this problem, i hope you are fine
    sir i tried to put new tanks as you mentioned , but these tanks cant be purchased in shop,
    lot of people have same problem , so if you kindly make a tutorial for simply add new tank that can be purchase-able in shop
    Iam working on this project from months and i stuck here i hope you can help me
     
  11. Luke-Lamothe

    Luke-Lamothe

    Joined:
    Feb 6, 2013
    Posts:
    2
    @fnaveedshah, @AlecLarsen1989 responded to you previously above and said that if you are able to send him your full console log, he may be able to help you track down what is breaking on your side, so if possible, you should probably take him up on his offer :)
     
  12. fnaveedshah

    fnaveedshah

    Joined:
    Dec 15, 2013
    Posts:
    6
    @
    Luke-Lamothe actually i give up , worst support experience in unity , moving to unreal engine
     
  13. theferfactor

    theferfactor

    Joined:
    Dec 16, 2016
    Posts:
    1
    Thank you very much for this reference project, it's really amazing.
    I have just one question
    How can I make a local LAN multiplayer out of this?
     
    frank28 likes this.
  14. sajjad2000

    sajjad2000

    Joined:
    Jul 6, 2017
    Posts:
    1
    Hi.I recently imported Tanks reference project from asset store to a new project without any changing or deleting or adding anything.when i want to build it for android,it shows me this error:unable to convert classes into Dex format! I Know that i must delete duplicate files but i still cant build it!!!!! Ok,If my project and their project is the same,so how they published it for android in google play?
     
  15. Tomahawkppc

    Tomahawkppc

    Joined:
    Jul 31, 2012
    Posts:
    8
    Hi, has anyone tried to integrate a password for a private lobby? Cheers!
     
  16. wioluskaelk

    wioluskaelk

    Joined:
    Aug 22, 2015
    Posts:
    13
  17. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    60
    Hi,

    I am trying to bundle the scenes to the AssetBundles, download them to the Application.persistentDataPath and load relevant scene at the Network Manager.

    Network Manager loads the game scene by ServerChangeScene(map.name);

    However, I need one previous step to load scene from asset bundle and progress to the scene, something like following:

    string scenePath = myLoadedAssetBundle.GetAllScenePaths()[0];
    SceneManager.LoadScene(scenePath);

    When I follow above steps with AssetBundles and use them at the NetworkManager, since I do not load my scene using ServerChangeScene method, I can not follow next steps of Networking and can not load the CompleteTank.

    Any ideas to help?
     
    Last edited: Oct 20, 2017
  18. JohnyDaison

    JohnyDaison

    Joined:
    Jul 27, 2017
    Posts:
    1
    Hi,
    I imported this project into Unity 2017.2.0f3 and everything works, but the tanks have shorter firing range. I checked the Physics settings and everything seems to be set up according to the PDF. Everything else seems ok, comparing with the youtube video, but the projectiles just don't fly as far as they should. I didn't make any changes except multiplayer setup before building the game. Anyone has any idea how is this possible?
     
    csivek likes this.
  19. GoRiLLa

    GoRiLLa

    Joined:
    Oct 8, 2013
    Posts:
    14
    I have the same issue, making it impossible to complete first Training mission.

    Even worse, I am not able to create any multiplayer games as it immediately fails upon creating game.
     
  20. FrancoFresco

    FrancoFresco

    Joined:
    Aug 1, 2012
    Posts:
    2
    Thanks for this reference project! it's actually a lot of fun! Shooting works fine for me (playing in the editor, 2017.2)

    Like GoRiLLa, I too am experiencing failing at creating a game.

    In editor
    - open splashScreen scene
    - click through then click Create Game
    - Give a server name and hit start
    - See prompt, "Failed to create game"

    Checked log and I'm not seeing any error messages.

    I did have to update the APIs to complete the import from the Asset store.
    I'm thinking has to do with this. I'm very new to UNet, so not exactly sure where to look to fix it.

    I'd love to learn from this.

    Thank you!
     
  21. FrancoFresco

    FrancoFresco

    Joined:
    Aug 1, 2012
    Posts:
    2
    In CreateGame.cs

    private void StartMatchmakingGame()
    {
    m_NetManager.StartMatchmakingGame(GetGameName(), (success, matchInfo) =>
    { ... });
    }

    It's definitely failing here.

    Where is "matchInfo" declared? I'm not even sure how this compiles..

    Thanks!
     
  22. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    @JohnyDaison @GoRiLLa @FrancoFresco

    Failed to Create Game
    If you're getting "Failed To Create Game" whenever you try to start a multiplayer match it's most likely because you haven't setup the Unity multiplayer service correctly or at all. Please read the "TanksReference" PDF file included in the root of the project for information on how to do this.

    Projectile Firing Issue
    Fired shells are supposed to land wherever you click/tap on the screen, but this is no longer the case in Unity 2017.2. After checking out what's new I noticed that they added a new physics related feature:
    I immediately suspected that this was the cause of the issue, however, messing with these new settings seemed to have no effect, so I scoured the source code and finally found the culprit in Shell.cs, line 135:

    Code (CSharp):
    1. // Face towards our movement direction
    2. private void Update()
    3. {
    4.     m_Transform.forward = m_CachedRigidBody.velocity;
    5.  
    6.    // Spin the projectile
    7.    m_CurrentSpinRot += m_Spin * Time.deltaTime * m_CachedRigidBody.velocity.magnitude;
    8.     m_Transform.Rotate(Vector3.forward, m_CurrentSpinRot, Space.Self);
    9.  
    10.    // Enforce minimum y, in case we go out of bounds
    11.    if (m_Transform.position.y <= m_MinY)
    12.    {
    13.        Destroy(gameObject);
    14.    }
    15.    else
    16.    {
    17.        // Reset this. We can set it to true during bounces to stop multiple colliders hitting it per frame
    18.        m_Exploded = false;
    19.    }
    20. }
    You simply need to move this snippet of code from Update() to FixedUpdate() and projectiles will land in the intended location once again. Hooray!

    Apparently this new physics feature has an adverse effect on any modifications made to the transform outside of FixedUpdate.

    Happy coding!

    @richard-lee @AlecLarsen1989 this projectile bug should really get an official patch ASAP because as GoRiLLa has pointed out already, it makes completing the first training mission nearly impossible and I'm sure this will cause a lot of support requests and confusion if not addressed soon.
     
    Last edited: Dec 12, 2017
    ibyte and Le_Tai like this.
  23. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    851
  24. cj31387

    cj31387

    Joined:
    May 23, 2012
    Posts:
    136
    Is this project fully authoritative ?
     
  25. Ghost004

    Ghost004

    Joined:
    Jan 27, 2016
    Posts:
    3
    Hello, I'm trying to add a tank (followed the post above and added tank to library)is there something else I need to do?

    Unity version 2017.3.1f1
    fresh project and tanks import

    getting index out of range error when I try and purchase.
    upload_2018-3-21_20-18-37.png
     
    Last edited: Mar 28, 2018
  26. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    @Ghost004 @fnaveedshah @wioluskaelk

    IndexOutOfRangeException: Tank index is invalid
    Hi @Ghost004, think I found the cause of this. It's a very tricky and somewhat dishonest bug, so past advise was not actually correct. The error appears to be caused by loading old save data that doesn't account for the increased number of tanks.

    The easiest solution I've come up with for this is to not load any save data the first time you enter play mode after changing something. New save data will then be automatically created once you exit play mode, overwriting the old data and updating the tank count. You can then start loading saved data again as long as you don't change anything.

    I did this in the project by simply adding a m_LoadSavedData boolean at the top of the PlayerDataManager class. Then I simply check if this variable is true before loading any data on line 145. So I can now just uncheck this option in the editor before entering play mode when I want to overwrite and update the save data.

    load_saved_data_option.png

    This will of course also erase all earned currency. So for testing I also created a Cheats script and attached it to the PlayerData game object with this code inside so I can test unlocking tanks.

    Code (CSharp):
    1. using Tanks.Data;
    2. using UnityEngine;
    3.  
    4. public class Cheats : MonoBehaviour
    5. {
    6.     void Update () {
    7.  
    8.         if (Input.GetKeyDown(KeyCode.M))
    9.             PlayerDataManager.s_Instance.AddCurrency (100);
    10.     }
    11. }
    A better way to do this would be to create a game version string variable. Then overwrite old save data every time this string value changes (e.g. "1.0" to "1.1"). This way it works for both editor and player builds so players will not get errors if you update your game and they load incompatible save data. However, implementing this requires more work. So I'm just sharing my simple solution here.
     

    Attached Files:

    zt3ff3n likes this.
  27. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    15
    Thanks for posting these updates and fixed @IsaiahKelly, I just started my first project - using this template to learn from, and I'm not too smart with code o_O.

    However, your previous post regarding the Projectile Firing Issues, and the proposed fix of replacing
    Code (csharp):
    1. private void Update()
    to
    Code (CSharp):
    1. [CODE]private void FixedUpdate()
    [/code] gives me an error.

    Assets/Scripts/Shell/Shell.cs(128,16): error CS0111: A member `Tanks.Shells.Shell.FixedUpdate()' is already defined. Rename this member or use different parameter types

    // Nevermind.
    I misunderstood you, and renamed that the update function. *Moving* its content to the above fixedupdate function does indeed work!
     
    Last edited: Apr 24, 2018
  28. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    @zt3ff3n Glad you found it helpful :). Yes, FixedUpdate is already defined in the script and you can only define that type of method once per script. So you need to move the code over instead of just renaming the method.

    You could also just rename the update method to something else completely like "ProjectileUpdate" and then call that from inside the FixedUpdate method instead. In fact, doing so is usually recommended because it allows you to easily move code execution around later if you need to.

    Best of luck with your project!
     
    Last edited: May 2, 2018
  29. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    15
    I'm trying to access the value for the tanks health, but so far not having any luck.
    Though I'm a pretty poor programmer, according to tons of googling, this should work - however it only outputs "health: 0 / opacity 1" in the debug. I attach this script to a world object I want to change the materials alpha value of according to the players health..

    - I can't even seem to find the code where the magic for the healthbar-circle is located to have a look at that. A push in the right direction would be pretty welcome!


    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5. using Tanks.Map;
    6. using Tanks.Explosions;
    7. using Tanks.Data;
    8.  
    9. namespace Tanks.TankControllers
    10. {
    11. public class MatScript2 : MonoBehaviour {
    12. //private float tanksHealth;
    13. private float healthOpacity;
    14.   void Start()
    15.     {
    16.  
    17.   float tanksHealth = GameObject.Find("CompleteTank").GetComponent<TankHealth>().m_CurrentHealth;
    18.   float healthOpacity = ((100 - tanksHealth) / 100);
    19.  
    20.        Debug.Log("Hello TANK");
    21.        Debug.Log("health: " + tanksHealth);
    22.        Debug.Log("opacity: " + healthOpacity);
    23.      }
    24.     void Update ()
    25.       {
    26.  
    27.     gameObject.GetComponent<Renderer>().material.SetFloat("_Alpha", healthOpacity);
    28.       }
    29.  
    30.  
    31.   }
    32. }
    33.  
    34.  
     
  30. Reshad

    Reshad

    Joined:
    Mar 23, 2013
    Posts:
    4
    Hi, I want to change this game for 2 players only. I don't want to create and join. I want to connect directly and go to game scene like clash royale. Is this possible? If so how??
     
  31. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    @zt3ff3n Sorry for the late reply. Haven't checked this tread for some time.

    First off, using GameObject.Find is generally a bad idea because there's way too much room for error. For example, your code will only find game objects with the exact name "CompleteTank", but since all tank prefabs are instantiated at runtime, the name will actually be something like "CompleteTank(clone)2", so this will never find it!

    A better choice would be to use FindObjectOfType instead, which finds the actually component itself, regardless of game object name:

    Code (CSharp):
    1. float tanksHealth = FindObjectOfType<TankHealth> ().m_CurrentHealth;
    However, this code will only return the very first instance of TankHealth it finds, and since this is a multiplayer game, that might not be the one you want. You could use FindObjectsOfType instead, which returns an array of all active TankHealth components, but this still doesn't help you figure out which one you actually want.

    In any case, trying to find the health component from another object is probably not the best way to go about this because it's very likely to break and lead to issues if you ever change or expand things in your game. So it's probably much better to have something on the tank prefab itself handling this.

    The health bar element is controlled by the HUDCanvas prefab found in the Prefabs/UI folder. It has a script attached to it called HUDController that communicates with the GameManager to subscribe to tank health change events, so it can update the UI display. Examining these scripts should hopefully help guide you in the right direction to get your game mechanic working.
     
    Last edited: May 26, 2018
  32. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    Anything is possible, it's just a matter of how much work is required. To change max players go to the NetworkManager component and change "Multiplayer Max Players" to 2.

    You will then need to modify or replace the LobbyPanel component if you want to eliminate the lobby system all together, but that is far too broad a subject to answer here. I would suggest reading the manual and checking out the Simple Multiplayer Example for help doing this.
     
    Last edited: May 26, 2018
  33. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    @newbeep You'll want to open the script named SinglePlayerCompleteModal and go to about line 139 where you should see this:

    Code (CSharp):
    1.  
    2. if (!success)
    3. {
    4.    achievementObject.SetToFailedState();
    5.    Vector2 newPanelSize = m_MainPanel.sizeDelta;
    6.    newPanelSize.y = m_FailedPanelHeight;
    7.    m_MainPanel.sizeDelta = newPanelSize;
    8.    break;
    9. }
    10. if (success && objective.lockState == LockState.NewlyUnlocked)
    11. {
    12.    m_AchievementsToPlay.Add(achievementObject);
    13.    achievementObject.SetUpCurrencyReward(objective.currencyReward, m_CurrencyAmountDisplay, currentCurrency);
    14.    currentCurrency += objective.currencyReward;
    15. }
    16. else if (objective.lockState == LockState.PreviouslyUnlocked)
    17. {
    18.    achievementObject.AlreadyAchieved();
    19.    achievementObject.animator.Play(m_AchievedAnimationName);
    20. }
    21. else
    22. {
    23.    achievementObject.SetCurrencyRewardText(objective.currencyReward);
    24. }
    25.  
    The LockState check and SetUpCurrencyReward method is key here. You can simply remove the LockState check from the if condition and the followup else statements to let the player get rewarded every time they complete an objective.
     
  34. SharkTeam

    SharkTeam

    Joined:
    Jan 28, 2016
    Posts:
    5
    Hello everyone,

    Can someone help me which scripts should I remove in order to be left only with a working lobby scene (Create Match, Find Match, choosing player, settings, quit)? Also I would like to be able to choose maps and game modes etc, I just wanna remove all the gameplay scripts...I'm planing on using a bit different gameplay so this gameplay is not an option, but lobby system is build really well so.. :)

    Thank you in advance!
     
  35. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    229
    @SharkTeam If you're mostly interested in the lobby system itself then it would probably be easiest to just use the Network Lobby example instead and modify it to your needs.

    However, if you want to use the game mode and map selection logic from this project it will require a bit of work since it's directly connected to the gameplay logic. So you'll first need to study the code to understand what exactly you want/need to strip out. e.g. do you want to keep cosmetics, damage, projectiles, etc. ?

    Most of the gameplay specific logic is located in the Scripts sub-folders "Tank", "Shell", "Rules", and "Powerups". So those are good places to start, but this will not be a super simple modification! So I would also highly recommend using some kind of version control system (e.g. Unity Collaborate) if you decided to try and modify the project. That way you can easily undo any change that breaks the project entirely.
     
  36. SharkTeam

    SharkTeam

    Joined:
    Jan 28, 2016
    Posts:
    5
    Thank you for a fast reply!

    Yes im aware that it wont be a simple modification.
    Unity Collaboration is actually a great advice thank you for that.
    My plan is to remove the way tank moves, fires etc and scripts for decorations and tank stats, but i want to keep a game mode and map logic as you said.
    I will start with subfolders that you mentioned and see where it will lead me.
    I just wanted to know where is the specific gameplay logic mostly located so thanks :)
    My plan is to have a third person character so thats why that part of gameplay is not necessary for me
     
  37. And1love

    And1love

    Joined:
    May 23, 2018
    Posts:
    1





    Hello) I`m new in unity. But... if you want something like cool down or delay you must ADD some new variables like TimeBetwShots, or make it with IEnumerator. I`ve learn much from "CooldownTutorials" and i have made a cooldown Buttons with nice Effect. look for this man "BlackThornProd" in youtube, he simply teached you about delay in shoots.
     
  38. RuslanBekniyazov

    RuslanBekniyazov

    Joined:
    Jun 29, 2018
    Posts:
    1
    Hi, is that okay if I use some parts of this project for my project that I plan to release (music for example)?
     
  39. TygoW

    TygoW

    Joined:
    Nov 20, 2017
    Posts:
    1
    Hello, how do i add a tank i have added a tank to the tank library but it still gives the error "Tank index invalid".
    can someone please help?

    it only works when i delete an other tank i can only have 3 tanks
     
    Last edited: Aug 20, 2018