Search Unity

TowerDefense ToolKit 4

Discussion in 'Assets and Asset Store' started by songtan, Apr 18, 2012.

  1. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    so where is all the magic happening during building like the progress bar and the handling of the countdown..i must deface it and make work differently ...i hate having to mod your code but it must be done...but where is that...
     
  2. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    The count down happens in UnitTower.cs, Construction(), called from FixedUpdate().

    All the code for progress bar is in UIOverlayConstruct.cs.
     
  3. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
  4. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    ok here is another one for you, i dont know how to ask,i have have designed a load and save game option , that means from a file i load towers manually and place them on the scene..ive done other modification to make this work with your guidance but whats broken now is the "UITowerSelect" dose not show when you try to select a tower i put in by script...any ideas why the info window doesn't show up?
     
  5. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Well I can't say. This will probably require step by step debug to find out why. The code in question starts from OnCursorDown() in UIControl.cs. You need to check if sInfo.GetTower()!=null return a true when you click on the tower. If not, then you will have to check TowerManager.GetSelectInfo() to find out why.

    The most likely case is when you place the tower into the scene, you didn't register them to the platform's node. Which is why the selection code detects no tower when they check the node.
     
  6. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    sound about what i guessed thanks...
     
  7. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    dose the add tower do this "registering"?
     
  8. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    i managed to rig it to work i think. i added a collider and a simple script
    Code (CSharp):
    1. void OnMouseOver()
    2.     {
    3.         //If your mouse hovers over the GameObject with the script attached, output this message
    4.         Debug.Log("Mouse is over GameObject." + tag);
    5.  
    6.  
    7.  
    8.  
    9.         //Debug.Log (sInfo.GetTower().tag);
    10.    
    11.  
    12.  
    13.  
    14.         if (Input.GetMouseButtonUp (0)) {
    15.             UnitTower Tu = GetComponent<UnitTower>();
    16.  
    17.             SelectControl.SelectUnit(Tu);
    18.             UITowerSelect.Show(Tu);
    19.            
    20.         }
    21. }
     
  9. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    Hey Song, just wanted to inform you that ur Path.CS script gets jumbled up with Unity System.IO.Path.

    Just so you know it might be best to rename that. I went ahead and added System.IO. in from of the API I needed. But in case someone else is less informative of how that works, it would be good to rename that class.

    Just a thought hope all is well :)

    https://docs.unity3d.com/ScriptReference/Path.html
     
  10. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Hi, I've just started using this asset a few weeks ago and I really like how it is structured.
    I quickly ran into two problems that I haven't been able to solve myself. I'll post the first one in here and the other in a subsequent post to keep things organised.

    Matching tilemap tilesize to platforms or vice versa. I can't seem to get the sizes to match. Right now I add a grid and a tilemap and adjust the scale in Grid to match a 1x1 platform as I close as I can and continue from there.

    I live in Europe, is the unit system mismatching? Should I change something there?
    Should I add a platform as a centered tile on a different tilemap layer or will that only break things?
     
  11. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    So here's the second question.

    Homing missile:
    At some point I'd like to adjust the speed of a bullet. I think the cannon already has a homing bullet, so if I could bring the speed down and change the sprite I've got a homing missile, right?
     
  12. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Sorry all for the slow respond. For some reason I have stopped receiving notification about new post. Also I've been super busy with my game release.

    @Chaz32621, Thanks for letting me know. I'll do something about it in the next update as soon as I find time.

    @Ferdi18, I dont quite understand what is the tilemap you are referring to. Perhaps you can show me a screen shot? As for your second question, that's the idea. You swap out the default visual element and put in whatever you fancy.
     
  13. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    @Ferdi18, I dont quite understand what is the tilemap you are referring to. Perhaps you can show me a screen shot? As for your second question, that's the idea. You swap out the default visual element and put in whatever you fancy.[/QUOTE]

    Hi, thank you for your response. For the tilemap part:
    https://docs.unity3d.com/Manual/Tilemap.html


    It basically allows you to draw 2D environments sprites (tiles) in a modular fashion. But I could broaden my question to 3D scenery as well. How can I match the 1x1 platform size in the toolkit, to make it easier to build levels in a modular fashion. I will try and add a picture.
     
  14. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Just for clarity sake, I'm going to use the unity scale as the reference. So when I say 1, it means the scale of the transform is (1,1,1). Basically how big it's if you create a default cube.

    Now to the question, I think the first thing you need to do is to determine what are the scale used in your tile map. The scale use in TDTK is very simple. Whatever you set in the gridsize in TowerManager is what you get in the for size of each individual build point. So if you can determine the size of each tile in your tile map (in unity scale), then you can simply set the grid size to match.
     
  15. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    I'm sorry for my late reply, I don't now how to change the setting to receive a notification after a forum response. I've been comparing both the platforms and the tilemaps to a regular cube and they both match the standard cube. I'm not sure what did wrong earlier, (I think I must have switched between orthographic and perspective mode incorrectly or it tried snapping to the wrong gridlines).
     
  16. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    So you have got it working now? If not, show me a screen shot of how are they not aligned. It's easier to figure things out from an image.
     
  17. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Yes, I have it working. This makes it a lot easier to to create artwork for the game. Thank you for your quick responses.
     
  18. primarygod

    primarygod

    Joined:
    Jan 16, 2017
    Posts:
    9
    hey songtan, again I am highly satisfied and impressed by your work. I am wondering tho. Can I merge TDTK with TDS-TK. I mostly mean about spawning and creeps. Are there gonna be hardcore conflicts. I am a developer so I can handle few changes I don't expect it to happen with few magick buttons, but still if it needs rewriting whole systems then its not much worth it.

    Let me explain what exactly I want to achieve. I am using TDTK as base, I created huge environment and huge gameplay. Now I am integrating some multiplayer stuff but I want to add creep spawning from TDS-TK and the random chasing creeps around.

    I am most worried for editor. If I do that am I going to have 2 creep editors and 2 spawn editors in my editor menu?

    Another thing I am imagining to use is the camera pivot and player from TDS-TK into TDTK so I can have some RPG into the tower defense gameplay.
     
    Last edited: Sep 7, 2018
  19. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I should say that TDTK and TDSTK are not designed to be compatible with each other. However the code have their own name space so you should have no problem using them in the some project. Yes you will have 2 spawn editors but they are two separate editors editing different things. They shouldn't give you any problem. Same goes with the gameplay elements. Basically you have two independent game running simultaneously. With the exception of physical elements like colliders, they shouldn't affect each other at all.

    The bigger question here is if you have units from both TDSTK and TDTK in the scene, how do you get them to interact with each other? For instance, getting the towers from TDTK to detect and attack the hostile unit of TDSTK, and vice versa. I suppose you will have to write your own code extension for that. But if you are comfortable with coding, I don't think that is going to be a huge problem.

    As far as I remember, the camera script in TDTK are mostly detached from the core gameplay logic. So you can just ditch that and just the one in TDSTK if you want.

    I hope this answer your question.
     
    primarygod likes this.
  20. primarygod

    primarygod

    Joined:
    Jan 16, 2017
    Posts:
    9
    that sounds great, I think I can handle it. Thanks for your help. I can't wait to show you my game created thanks to you.
     
  21. primarygod

    primarygod

    Joined:
    Jan 16, 2017
    Posts:
    9
    also another question, I'll figure it out anyway but just in case I'll ask. I am planning to create paths dynamically ingame. Can you guide me the DB file which I need to fork in runtime so I can add more paths (and destroy paths).
     
  22. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Path are instances in the scene. There's no DB file involved. It's all in Path.cs.
     
    primarygod likes this.
  23. primarygod

    primarygod

    Joined:
    Jan 16, 2017
    Posts:
    9
    sorry songtan I need to know one last question. I am really sorry I hate to be that disturbing and I promise thats my last.
    Can you guide me where the waves from SpawnEditor are stored so I can also fork them in runtime. Or may be its better if I would use your spawnManager.cs functions to generate waves (as I can see you already have pretty usefull functions).

    P.S. feel free not to answer my question I will figure it out eventually, I am just asking here to save me some research time.
     
  24. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    No worries. It's my job to answer questions. :)

    The waves you are editing in the editor are waveList in the SpawnManager component in each scene. If you are referring to the class definition, it's in SpawnManager.cs if I remember correctly (sorry I'm travelling this week so I don't have access to my work computer to confirm).
     
  25. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198

    Hey song sorry to bother you. I'm sure you are super busy with another great project!

    I was just wondering if you could go over the logic of how the ability casting works on Mobile. I am trying to modify the target part more so. But would like to just see the logic and a better explanation of that part. Just a nice run down of it.


    Also any chance on a new update? Been some time lol
     
  26. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    The ability casting on mobile is not different from how it works on pc. In short, whenever an ability is selected, a check is performed if the ability require any target. If not the ability will be cast, otherwise the input on UIControl is set to target mode. So any cursor event is pass to AbilityManager for a target validity check. If it's the selection is valid for the position selected, the ability is cast on that position. The relevant code is in UIControl.OnCursorDownAbilityTargetMode().

    I have no plan for any new update to be honestly. There hasn't been any feature that I like to add at the moment. Plus I have been busy with other stuff so I haven't been spending a lot of time playing with potential ideas.
     
  27. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    Thanks song this helped alot! There are a few new additions I could see adding.(Ive added most by modifying your code but it would be cool to see)

    - Updated spell indicators which also size with the AOE radius of the spell
    - Spells based off a line cast - instead of just a O.
    - Spells that are based off a line cast introduce a system that allows user to pick 2 points to cast the spell point A point B. Of the line A to line B.
    - Mix spells for a powerful cast.

    I have a few others but cant think of them off the top of my head. Anyways, getting closer to wrapping up development for my game. So you'll get to see my modified version!
     
  28. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi songtan.
    Need help with programming, Need to automatically save the resource perk. The script is like this. No errors, no saving. What am I doing wrong?
    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

  29. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    You mean save the resource value? The code looks fine. The question is where do you call these function?
     
  30. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi songtan.
    Yes, I want to save. Automatically. Before leaving the game.
    Where to call a function? In RscManager.cs? How to call her?
    What to change, add to PerkManager?
    Thanks for the help.
    Sorry for my English.
     
    Last edited: Sep 28, 2018
  31. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Please define 'leaving the game'. Quit game the middle of a gameplay level? Or when the level is completed? Or quit the game from the main menu (not in a gameplay level)? How does it work when you start the game again? It always uses the load value again when you goes into a gameplay level? Even when you start a new level?

    Depend on what you really need, you may need to call those function from different places.
     
  32. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi Songtan.
    Yes. The saving level is complete.
    Work as a screenshot
    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

  33. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    In that case you need to call the load function when the game start and call the save function when player completed the level. You can add the load function call in Awake() of RscManager and add the save function call in EndGame() of GameControl (under the condition playerWon).
     
  34. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi Songtan.
    What exactly should write in
    RscManager.cs?
    GameControl.cs?
    which line?
    Thanks for the help.
    Sorry for my English.
     
  35. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Now as in the screenshots.
    This does not work
    What is wrong?

    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

    Last edited: Oct 4, 2018
  36. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Sorry for the delayed respond. Everything seems ok, except the line in RscManager.cs. You need move your code to the last line of Awake(). Also, it should have been rscList=TDPerkRes.LoadRsc();.
     
  37. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi Songtan.
    Moved
    Now two errors
    screenshot
    What is wrong?

    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

  38. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I meant move your code to the last line of Awake() in RscManager, instead you have moved it to the last line of CachedRsc(). Also it's rscList=TDSaveRes.LoadRsc();. My bad for the typing error.
     
  39. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi Songtan.
    Saving works. But after the game is turned off, the value is reset to 0.
    (After exiting the game, the value is reset to 0)

    Maybe the value is set earlier? What is my save loaded with? screenshot

    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

  40. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I think you have misunderstood. The resource value in PerkManager is has nothing to do with RscManager. That is an entirely different variable use exclusively for perk only. So far everything that you have done only save and load the resource values in RscManager.

    For what you need, you need to save the variable rsc in PerkManager.cs in CachedProgress(), and load it in last line of Awake().
     
  41. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    I'm sorry, I did not understand.
    Need to change in PerkManager.cs?
    Change as in the screenshot?

    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

  42. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Forget about TDSaveRes.SavePerkRes() and TDSaveRes.LoadRes(). These function save and load the resource value in RscManager. They have nothing to do with PerkManager.

    Instead, you can just use a simple PlayerPref.SetInt("perkRsc", rsc); in CachedProgress() and PlayerPref.GetInt("perkRsc", rsc); in Awake().

    For Awake(), don't put the code in the loop. Move it to the last line instead.
     
  43. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Does not work. 2 errors.
    What's wrong ?

    Assets/TDTK/Scripts/PerkManager.cs(84,5): error CS0103: The name `PlayerPref' does not exist in the current context
    Assets/TDTK/Scripts/PerkManager.cs(135,4): error CS0103: The name `PlayerPref' does not exist in the current context

    Thanks for the help.
    Sorry for my English.
     

    Attached Files:

    Last edited: Oct 12, 2018
  44. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    It's just typing error. Change PlayerPref to PlayerPrefs.
     
  45. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    What's wrong ?

    Fixed. (Change PlayerPref to PlayerPrefs.) Now

    Assets/TDTK/Scripts/PerkManager.cs(134,43): error CS0120: An object reference is required to access non-static member `TDTK.PerkManager.rsc

    Thanks for the help.
    Sorry for my English.
     
  46. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Try PlayerPrefs.SetInt("perkRsc", instance.rsc); in CachedProgress().

    For Awake(), I notice an error in the code I gave you. It should have been instance.rsc=PlayerPrefs.GetInt("perkRsc");
     
  47. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Thanks, it works now
     
  48. ppmpyae7

    ppmpyae7

    Joined:
    Sep 13, 2018
    Posts:
    13
    Hi,I want to know if you can support the enviroments of the tower defense.Now,it looks only like a use less one without any art apart from basic features of tower defense.Thanks for reading
     
  49. ppmpyae7

    ppmpyae7

    Joined:
    Sep 13, 2018
    Posts:
    13
    And also,a level editor please?
     
  50. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    You are free to add any art asset required for your game. TDTK is designed with integration of 3rd party art asset in mind. The package provide you a framework for a your own custom TD game, not a premade one with fixed game play and art.

    I'm not entirely sure what you mean specifically by 'level editor', but there are various editors for various purpose. SpawnEditor to configure the incoming waves. TowerEditor to configure tower stats and so on...