Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TowerDefense ToolKit 4

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

  1. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    so SpawnManager.AddActiveUnit(unitInstance); makes a tower enemy
    can you make creep enemies out of other creeps..cause thats what i think im going to do

    and suggestions before i get to butchering your beautiful code

    Code (CSharp):
    1. GameObject unitObj = (GameObject)Instantiate(HardEnemy, path.GetSpawnPoint(), Quaternion.identity);
    2.                 UnitCreep unitInstance = unitObj.GetComponent<UnitCreep>();
    3.                 unitInstance.Init(0, path);
    4.                 if (!Freindly)
    5.                   //  SpawnManager.AddActiveUnit(unitInstance); // make enemy attack
    6.                 TowerManager.AddTower(unitObj);//make a enemy of the creeps? looks like it will need modifications
    hell mabey i will make it so they will be enemys to both.. both creep and tower all at once and see what happens
     
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    It won't work as it's. TowerManager.AddTower() takes UnitTower type, UnitCreep. And the function add the UnitTower instance to a UnitTower list. In order for that to work, you need to have UnitTower attached to your creep prefab. You can't probably see why that wouldn't work.

    If you want a unit which is both targeted by the creep and tower. You will be better off changing the targeting code.
     
  3. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    i see.. but it will be fun to do .. .. i wanna add all your stuff from the top down shooter to this all the weapons types they look kool.. ohhh as a hint where is that targeting code located?
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    The code for targeting is in Unit.cs. Look for the function ScanForTarget().
     
  5. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    so ive tryed alot things and your suggestion from a year or so agoe
    i cant get a a platform to format at runtime for the life of me.. here is the old code we tried .. and i see you have some code snipits in there that almost look like what i need but they are missing some details..
    its late ive been trying to figure hot attach one those nodes for far to long now
    Code (CSharp):
    1. public class TowerManager : MonoBehaviour {
    2.        
    3.         ////https://forum.unity.com/threads/towerdefense-toolkit-4.132736/page-43
    4.         public static void FormatPlatform(BuildPlatform platform){
    5.             platform.Format(GetGridSize(), instance.autoAdjustTextureToGrid);
    6.         }
     
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    The code seems fine. Can you describe in what way that wouldn't work?
     
  7. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    ive placed it un update and with repeat invoke and it did work .. ill go back and and try a fresh install see what happens
     
    Last edited: Mar 29, 2019
  8. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    i place a platform on a tower block above it and add this code the the platform with the buildplatform component on it
    and the build a block tower and durning runtime i expect to be able to stack block towers but it dose not initiate the nodes and grid and wont let me stack them.. i dont get it, this is all runtime active .. but it wont works.. if works if you add them by the editor and play the game.. the other half of the code was posted earlier
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using TDTK;
    5. public class FormatPlatform : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         BuildPlatform platform= GetComponent<BuildPlatform>();
    10.         TowerManager.FormatPlatform(platform);
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.        
    16.     }
    17. }
    18.  
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I just did a quick test trying to achieve what you are looking for. Here's something to note. What build mode you are using? The thing is Format() adjust the platform size and setup the nodes on the platform (which use to determine the build spot and path-finding). The nodes are fixed to the world space. That means if you are using a drag-n-drop, Format would have been called the nodes would have been setup at where the tower is first instantiated, not where you place it.

    What you can do is use drag-n-drop mode. Or change your script to only call the format function when the tower has been placed down.
     
  10. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    75
    Reformatting the towers at run-time is something I've looked at in the past too. After seeing Song's advice in this thread I've started a new scene and followed the advice. I have a script on the platform with this:
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         BuildPlatform platform = GetComponent<BuildPlatform>();
    4.         TowerManager.FormatPlatform(platform);
    5.     }
    6.  
    I added this function to my TowerManager:
    Code (CSharp):
    1.         public static void FormatPlatform(BuildPlatform platform)
    2.         {
    3.             platform.Format(GetGridSize(), instance.autoAdjustTextureToGrid);
    4.         }
    Here's an image of the problem I'm encountering: https://drive.google.com/open?id=1aGQk82L6ChN9FLOzNKL_OFCgUcsyG5WG - note the incorrect platforms above the block towers.

    I'm using drag and drop as Song recommended, but I'm not trying to integrate an inventory manager like wethecom. I'm just trying to make it so you can build platforms.
     
  11. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    im haveing scaling issues the platform is not scaled right... looks like you have to adjust your position on you prefer .. he has some code in there for make and adding a platform at runtime with addcomponent i need to try when i can get some clarity
     
  12. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm so sorry that I've only notice this now. What I meant to say is use Point-n-Click mode, where the tower will be instantiate where it's meant to be placed. Otherwise formatting the platform in Start() wouldn't have work.

    Another thing to note is the Format() function assume the platform transform has a base scale of (1, 1, 1) where the default obstacle tower's scale is not. So if you place the platform as a child object of the tower you will need to readjust the tower's scale to (1, 1, 1) otherwise the format function will not scale the platform correctly.
     
  13. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    75
    Cheers Song, that was an easy fix! I did suspect the scale might have been a factor with the grid being calculated. Changing Drag and Drop to Point and Click did the trick!
     
  14. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Hi, when I try to use the lightweight render pipeline (lwrp), I have issues with the OverlayCamera, UICamera & UICamera_Screen.

    The issue seems to be that they have opaque backgrounds and I'm not sure how to get rid of that.

    (Unity 2019.1.0f2, LWRP (5.7 & 5.10 & 5.13, I think)
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    LWRP doesn't support multiple camera. So to utilise it you will have to use only one main camera.

    For OverlayCamera, you can simply disable it. The overlay items will still be visible on main camera, just that they might get obstructed by other object in some cases.

    UICamera and UICamera_Screen are both for UI. You will need to change the Render Mode on all the Canvas to 'Screen Space - Overlay'. Then you can get rid of both the cameras. Using 'Screen Space - Overlay', you will need to make sure the sort order on the individual canvas are correct so that they get rendered in the correct order (Canvas with higer sort-order will appear on top).
     
  16. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Ah, thank you. That seems to solve the issues indeed!
     
  17. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    @songtan How can I adjust the flying height of the enemy? I cannot clearly see it anywhere.
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    There's no 'flight height' per se. You just adjust the y-axis offset of the model to the prefab origin to whatever you prefer. Of course you will need to adjust the target-point to match.
     
  19. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75

    • option for flying creep to bypass maze
    height is based in the animation controllers and is irrelevant to the flying your talking about. what a tough question
     
  20. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    can i use this is some way to make build nodes places tower can be built.. its in your code.. still trying to solve the stackable towers thing.. thought i think i have it ,i still wanna know..

    Code (CSharp):
    1. public void SingleNodePlatform(){
    2.             nodeGraph=new NodeTD[1];
    3.             nodeGraph[0]=new NodeTD(GetPos(), 0);
    4.         }
     
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You don't need to. Referring to our earlier discussion, what you need is to put a platform object on top of your tower prefab. If you are using PointNClick mode, things should work right out of the box.
     
  22. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    by you dont need to do you mean yes you can place those nodes manually? and use them to stack towers?
     
  23. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    there are scaling issues when you place a build platform on a prefab..so it has it be instantiated but im having issue instantiating it at the location i want to... but thats just me i can get that right later.. im not putting as much time as i should be into this project
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I don't understand what you mean by placing the node manually. I mean you can add a single node platform on top of the tower prefabs. When the towers are built, the player can built another tower on the platform on the tower, effectively allow tower stacking.

    You can always adjust the scaling so that it fits when it's instantiated
     
    Proto-G likes this.
  25. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    " single node platform on top of the tower prefabs. " that dose not work it has scaling issue with the towers it resizes it. it has to be instantiated after.. it shifts it position and location of the grid and if you adjust it just make it worse
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Yes the platform will be resize to fit the node size. But as far as I can tell if you keep your tower prefab scale at (1, 1, 1), you should be fine.
     
  27. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    but yours are not 1,1,1 and that means i would have have to rescale every thing... ..and the world i built with it... gonna have to find another way and i did.. i just have to implement it i instantiate just platform by itself.. or a node depending how testing works out
     
    Last edited: Jun 23, 2019
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Not really, you can change the the scale of the prefab to (1, 1, 1) while keeping the scale of everything the same. You just need to compensate by adjusting the scale of the child object of the prefab. A simple way to do is would be move all the child-objects of the prefab out of the hierarchy, adjusting the scale, then move the child-objects back to the hierarchy.
     
    Proto-G likes this.
  29. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
  30. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, I'm interested in TDTK full version and Unity's Free TowerDefense Template and wandering how they are different.
    I'm sure TDTK offers a lot more but I can't really tell from playing with TDTK free version.
    I would appreciate if you can let me know to make the decision easier.
    Thanks.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for your interest.

    The free version is basically a stripped down version of the full version. So basically it's just missing a bunch of features. The most noticeable one would be mazing and path-finding. In full version, you set grid of tower platform as a waypoint which the creep will have to find their way through as player build tower to obstruct the route (see some of the screen shot of the full version and you will get the idea). So instead of a linear path, you can have a much more interesting level design. Other notable missing features that I can recall on top of my head include perk system (for you to build a tech tree), ability system, branching tower upgrades, attacking creeps, procedural spawning and endless level. And of course various small touches that make the framework more user friendly.

    I should clarify that the free version is one based on TDTK3 while the latest is TDTK4. TDTK4 feature a much more powerful effect system that allows you to customize what each attack, ability and perk do. On top of applying the obvious effect like low and stun, it allows you to create effect that modify every stats on a unit (tower or creep).
     
  32. pastaread

    pastaread

    Joined:
    Sep 11, 2015
    Posts:
    2
    Hello, it's a great asset.
    One thing is that I cannot do.
    I have 2 starting points, I look at this scene 'Demo_Linear', but in my case these starting points share same platform (some waypoints and platforms) and system cannot identify real path in '_UpdatePath' function.

    TDK.png
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I don't see any reason why your setup doesn't work and I don't quite get what you mean by "system cannot identify real path in '_UpdatePath' function". Is it an error? If yes you will have to show me specifically what the error message is.

    I suspect it's something with your setting. I have quickly made some modification with the scene Demo_Linear to show what you need. Please refer to this screen shot.

    TDTK_Example.png
     
  34. Budgieboy

    Budgieboy

    Joined:
    Sep 6, 2012
    Posts:
    39
    Hey I have a problem, If I use freeform mode upgrading a tower doesn't work yet it works fine if I use build platforms.

    What happens is the new tower gets placed and is unselectable, I looked at the tower in runtime and noticed that placing the towers in freeform creates a build platform at the base so I tried creating one manually on the upgrade prefab but still no luck.
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You are right. I'll work on a fix and upload it asap. If you need it before then, please email me and I'll send you the fix in advance.
     
  36. pastaread

    pastaread

    Joined:
    Sep 11, 2015
    Posts:
    2
    Thanks, everything works perfectly. I have duplicated platforms and that was the reason.
    Thanks.
     
  37. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    Hello, im gonna buy the asset soon, as im still preparing some stuff, but im curious about two things:
    Can there be piercing shots? like damaging enemies in a line, but not in an classical explotion aoe.
    and could this toolkit work with a random map generation? (with having always the spawn point and the endpoint at opposite sides of the map)
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm afraid the answer to both your question is no.

    Piercing shot sounds like a good idea though. I'll see if I can add that in the next update (no promise though). As for random map generation, I don't think that's something that can be done given the open end nature of the path-platform placement supported by the framework. It can be done sure, but it's going to be very difficult to have an algorithm that can come up with a good level.
     
  39. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    ohhh.
    I just bought the toolkit. First of all, congratulations man, its excelent!
    I have a question that i havent figured it out yet, is there any way to make different height levels / ravines?
    like a place where creeps cant move through and you can build?
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for your purchase.

    What you can do is simply block off the section where the creep cant move through. Then place another build-platform higher than the blocked section. Make sense?
     
  41. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    yeah, it sort of works.
    I added a terrain (which includes the terrain collider), but the creeps seems to ignore it.
    I have some other questions:
    Can block/unblock an upgrade based on the perk system?
    Can i put more than one spawn point for creeps?
    and can i make a tower attack multiple targets at the same time?
     
    Last edited: Aug 23, 2019
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You need to set the layer to any obstacle intended to block out the platform to 26 in order for it to work. Please refer to the scene Demo_Platform for example.

    You mean tower upgrade? Unfortunately no. I'm surprise I haven't thought of this. I'll see if I can add it in the future update.

    Yes. What you do is have more than one path that starts at different places.

    No. Unless you use AOE Tower type tower. But instead of fire a shoot-object. It simply damage all creeps within range.
     
    MrZeker likes this.
  43. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    What im trying to do is make the creeps follow the terrain, if i put the terrain in the layer 26, it becomes a block and creeps ignore it, i cant build and half the time only one creep spawns in the whole wave, dont even know why.

    If i set it in the layer 31 i can build as i want, but the creeps just move through the mountains. Is there any way to enforce the creeps to follow the terrain colliders, but not block the building placements?
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm sorry but I don't quite get what exactly are the setup you are going for. Are there mazing involve? If you just want the creep to follow a fix path the terrain, you should just use a path with linear waypoints (please refer to the path setup in the scene 'Demo_Linear').

    If you want to block off section of the walkable build platform, you need to place collider with layer-26 on the area where you want to block. In your case, maybe using the terrain collider as a whole is not a good idea. I suspect due to the positioning, the terrain collider has simply blocked off the whole platform. Try use smaller box collider instead (with renderer disabled). By the way, by switching on the gizmo in GameView, you can see the node on the platform. White is normal node (you can build on it and creeps can go through), grey is for blocking out towers (creeps can still go through), red means the node has been blocked off completely.

    TDTK_Gizmos.png
     
  45. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    Thanks, this is what im going for:


    I added box colliders and that solved.
    Is it possible to block the way with towers so creeps will have to open its way throught breaking them? (essentially building walls se they get wrecked)
     
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I don't think so. The system doesn't support the completely blocked platform. But you can enable attacking for the creep so they can attack tower and possibly take out some of the tower you used to block the path. That say, they will attack anything so there's no guarantee they only go for the towers that block the path.
     
  47. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    I seem to be having some sort of bug, where i cant properly save Perks. When i hit save it doesn't save the perk im editing, but rather, saves Some of the stuff i changed on the next perk i select.
    what could be causing this?
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I have done some test. It's nothing to do with the save button. For now, you avoid this by pressing enter after you have done editing each field while I try to fix it.
     
  49. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Using the TurretEditor is causing Unity to crash occasionally when editing tower values. Has happened twice now and is kind of a big deal, just lost a lot of work. I'm using 2019.1.11f1 any ideas?
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Does it just crash randomly? Did you notice any specific thing that causes it? Any error in the console? I haven't experienced it but I haven't been using TDTK on Unity2019 much if I'm honest.

    Edit: I think I have found the problem. However I'm not sure if that's what cause the crash for you. So if you have further info, please let me know. Otherwise I'll upload an update shortly.
     
    Last edited: Aug 31, 2019