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. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    Thank you ;)
     
  2. unitythestars

    unitythestars

    Joined:
    Jan 20, 2021
    Posts:
    1
    Hello , How can i change the size of the platform. When I resize it , it will just add more nodes to it
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Try GridSize in TowerManager. Adjusting the scale of the platform only increase the size of the platform itself.
     
  4. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    Hi again here !
    I need to access the ressource with another script for a mini game (if the player win the minigame, he win some Rsc). But I can't find it. I've got 4 different Rsc in the game. I'm a little bit lost with the list. Is there a good way to get the variable and add or substract values ? Should I use SpendRsc and GainRsc ?
     
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    If you have a RscManager in the scene, just use SpendRsc() and GainRsc(). Like this:

    Code (CSharp):
    1. //Gain 10 first resource, 20 second resource, 30 third resource and 40 fourth resource
    2. List<int> gainList=new List<int>{ 10, 20, 30, 40 };
    3. RscManager.GainRsc(gainList);
    4.  
    5. //Lose 10 first resource, 20 second resource, 30 third resource and 40 fourth resource
    6. List<int> lostList=new List<int>{ 10, 20, 30, 40 };
    7. RscManager.SpendRsc(lostList);
     
    Proto-G likes this.
  6. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    27
    Hey songtan, I'm running into an issue after updating where some platforms are being marked "red" on runtime and receive the "Invalid Build Point" error (see screenshot). Which platforms are affected will sometimes change when I restart the level, but it's always at least one. Any idea why that might happen? Thanks!!
     

    Attached Files:

    Last edited: Apr 17, 2021
  7. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    Thank you for your answer Songtan.

    I had this issues when my terrain was not flag with the layer "Terrain", nnoom.
     
    Last edited: Apr 17, 2021
    nnoom1986 likes this.
  8. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    27
    Thank you for the suggestion! I gave it a shot, but unfortunately it didn't take care of it. I went ahead and removed all the terrain in the scene to make sure I wasn't missing something, just in case.
     

    Attached Files:

  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    There's only one reason why a platform is blocked from building, a collider (any game-object with any kind of collider component on it) is in the way. I would check your scene and remove any collider that is not the platforms. You don't need to remove the object entirely, just the collider component. If for some reason that collider is needed, try changing the game-object layer to 'Terrain' (Layer-31) so the detector will ignore it.

    Also I notice that you have Rigidbody on your platforms. You don't need those.
     
    nnoom1986 likes this.
  10. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    27
    Thank you. It does appear that if I remove the "Box Collider" from the Platform, it resolves the issue. But don't I need the box collider for the snapping to work?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I don't understand what snapping your are referring to. But no, other than the collider on the build platform themselves, no other operation in TDTK requires collider.
     
    nnoom1986 likes this.
  12. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    27
    By snapping, I mean when the tower gets close to the build platform and kind of "snaps" into place. Where it jumps to the center of the grid spot for proper placement.

    Check out this screenshot. I did a search for all colliders, and literally the only items with them are the platforms. Am I doing the Platform colliders wrong? Do they need a special layer or something? Note that if I disable the box colliders on the platforms, they work again, and this started happening after I updated the asset. It worked for a long time, previously.

    Is there another script that interacts and possibly marks them as not buildable?
     

    Attached Files:

    Last edited: Apr 17, 2021
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    It's hard to say what's really going on in your scene by just looking at the screen shot. If you don't mind, you can strip the scene down to just TDTK component and send it to me so I can take a look at it.

    The requirement for the build platform to work are just the script BuildPlatform.cs and a collider component attached on it. And of course, no blocked by other collider. I try it with my scene where I disable the colliders on the build platforms, they stop working. Not blocked but because the cursor can't detect them (the gizmo still show them as a white node).
     
    nnoom1986 likes this.
  14. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    27
    I started digging through the code and came across this:
    Code (CSharp):
    1. public static int GetLayerPlatform(){ return 29; }
    I noticed that I didn't have a "Platform" layer set as 29, so I created one. Once I assigned that layer to my platforms, it seems to have fixed the issue!
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm not sure if that matters to be honest. I've tried a case where I clear the layer setting and change the platform layer to default and it works just fine. Whatever works I suppose.
     
  16. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    Hi again Songtan
    All works fine with your help. Thank you.
    Maybe my last question:
    After decrease a ressource, how to check if the value is <= 0 ? I tried many things but none work... Any idea ?
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You can use RscManager.GetResourceList(). It will gives you a list corresponds to the current value of the resources. So if you want to check the first resource:
    Code (CSharp):
    1. List<int> rscValues=new List<int>( RscManager.GetResourceList() );
    2. if(rscValues[0]<=0) Debug.Log("first resource is <=0");
     
    Proto-G likes this.
  18. YevgenG

    YevgenG

    Joined:
    Oct 17, 2018
    Posts:
    22
    Hello, guys! @songtan Thanks a lot for all your support! :D I'm so glad that I've purchased this pack one day and now making TD of my dream, aah-ha :)

    Very quick question. Is there any localization asset from Unity Asset store you can recommend to be used with TD pack? Something like L2 localization or Lean Localization? The biggest question for me is how to localize text descriptions of perks, active abilities, that are stored in the config DB files :)
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Glad you are having fun. Unfortunately I don't have a lot of experience when it comes to localization so I'm not sure what would be the best localization pack to use. As for the text description, you will have to do a little modification. You need to remove the description text on the items (towers, perks, abilities) and have them pull it from somewhere else (a text/script file maybe). I imagine with localization, this is probably the only way how you can get the string in the corresponding language being returned based on the language selected.
     
    YevgenG likes this.
  20. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    Hi there.
    Is other have trouble with the last update ?
     

    Attached Files:

  21. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    and also with the RscManager and GameControl.
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    What version of unity are you using? Have you try re-import the package? To a blank project?
     
  23. Rage1789

    Rage1789

    Joined:
    Mar 20, 2015
    Posts:
    26
    I found why all my script were wrong with the new update, it's my fault,
    I don't know why but in the script GameControl the line 7 was change: namespace SpawnManager, and in the new script came with the new update it's: namespace TDTK, and of course it change many things.
    that why I've got error, all my script were based on SpawnManager... It was me that did a mistake, so... Sorry.
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    No worries. :)
     
  25. AntiGraphic

    AntiGraphic

    Joined:
    Mar 13, 2021
    Posts:
    1
    Hi there, i've been following this thread for a couple of years now, really great work, you and your asset are more than above avarage, fast replies and great comunication overall;

    However i have a visual problem regarding adding a muzzle flash to a 'projectile' type 'shoot object script'. The problem is that the muzzle flash does not face the same direction as the barrel of the turret (see screenshot).

    Thank you,
    Razvan.

    muzzle-flash-not-alligned.JPG muzzle-script.JPG
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks. I've just sent you a package. Please try that.
     
  27. mhonnibal

    mhonnibal

    Joined:
    Feb 22, 2021
    Posts:
    11
    Thanks so much song for your recent help!
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    No problem, glad to help.
     
  29. timschat

    timschat

    Joined:
    Mar 4, 2018
    Posts:
    3
    Using the latest 4.1 version, I cannot control the orientation of placed towers. I was supspecting that the orienation is controlled by the orientation of the platform. However, for me towers always point into the same direction, no matter how the platform is oriented. Also, when upgrading a tower, the orientation of the upgraded tower (new prefab) may change depending on the platform (maybe it starts working then?) Any ideas?
     
  30. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    The orientation of the tower is indeed based on the platform, when both building and upgrading the tower. I suspect there must be something on your prefab that change that after the TDTK script set the tower orientation. Do you have any other script on the tower prefab? If not, I'm guessing it's the animation. And if it's animation, is the animator on root-transform? Try follow the example prefab tower where the root transform is an empty object with just the UnitTower script, the rest is place under the hierarchy of that transform.
     
  31. timschat

    timschat

    Joined:
    Mar 4, 2018
    Posts:
    3
    Think its something else. The sample towers are affected as well, so its probably not about the construction of the towers. No matter how I rotate the platform, the towers point into the same direction after placement.

    However, when upgrading a tower the orientation is indeed adjusted to reflect the platform oriatination.

    In the sample picture, I set the rotation (for demonstration puproses) to 45 degrees and placed one of the sample towers (ignore missing materials, I am using URP). This is the direction that all towers are placed no matter what the platform is oriented. 2831.png
     
    Last edited: May 16, 2021
  32. timschat

    timschat

    Joined:
    Mar 4, 2018
    Posts:
    3
    One more (strange) issue I ran in: For one of my towers, the projectiles degenerate in scale of time. I have no idea why their scale is even touched. However, it seems to be related to the object pooling for projectiles where the projectiles are reused without restoring their original scale.

    So as a workaround, I added a line to reapply the original scale to Unit.cs.

    Still, I have no idea why the scale of the projectiles get modified at all. Does not happen when any other tower fires the same projectile. The only thing special about that particular tower is that some of its parts do have unkommon scaling values, but still I see no connection to the fired projectile.

    Nevertheless, I think it might generally make sense to have this line in as effects could modify the object scale as well. However, that may also happen to size or anything else, so where to stop?

    2832.png
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I think I see the problem with the tower orientation. While it's working in PointNBuild mode, it doesn't work that way in DragNDrop mode. I'll send you a fix shortly.

    Regarding the projectile scale, I think what happen is when a shoot-object is fired. It's placed as a child transform of the shoot-point (for making sure it follows the turret aim). So if your tower has any animation that change the scale, it's going to affect the shoot-object too. Anyway, the line of code you added should solve the problem.
     
  34. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Hey Song, hope all is well!

    I'm in the process of adding tower prefabs to a custom UI. Can you please help me reference the correct functions to make them work?

    I am using UI buttons with [On Click] [On Hover Enter] & [On Hover Exit] events.
    I'm then referencing the tower prefab in the project, not the hierarchy (because they load at run time).

    I'm using PointNBuild mode.

    Looking at the tower prefab, I can see there is a list of functions for UnitTower. I tried UnitTower - Build() but that didn't work. Also curious about the ToolTip, which I dragged in from the heirarchy.

    I'm also curious about DragNDrop mode. Which functions would be called...

    Thanks!
     
    Last edited: May 20, 2021
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Actually you don't call any function on the tower prefab. It's a little bit more complicated than that. For PointNBuild , you have to first get the information of the built point being selected, then pass that information, along with the tower selected to TowerManager by calling TowerManager.BuildTower().

    You can refer to UIBuildButton.cs. By default when a build-point has been selected (the code is in UIControl.cs), the information is passed to UIBuildButton, prompting the buttons to shows up. Then TowerManager.BuildTower() is called when one of the button is pressed (see OnBuildButton()).
     
    Proto-G likes this.
  36. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I want to be able to rotate each tower with button press during the preview (PointNBuild) and then have it build facing the current preview facing direction. What script/s would i need to modify and where? I have tried adding additonal input and rotation lines to TowerManager.cs but can't figure it out. Thanks
     
    MaxiMaximaal likes this.
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Just add the following in TowerManager.cs Update() to rotate the preview.
    Code (CSharp):
    1. if(Input.GetKeyDown(KeyCode.R)){
    2.     if(dndTower!=null){
    3.         dndTower.transform.rotation*=Quaternion.Euler(0, 90, 0);
    4.     }
    5. }
    6.  
    The tower will be built according to the preview rotation by default.
     
    Proto-G likes this.
  38. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Thanks!

    This works for DragNDrop mode, but I'm using PointNBuild mode. I was able to get it working.

    Code (CSharp):
    1. if(Input.GetKeyDown(KeyCode.R)){
    2. instance.sampleList[instance.activeSampleTowerIdx].transform.rotation*=Quaternion.Euler(0, 90, 0);
    3. }
    4.  
    5. GameObject obj=(GameObject)Instantiate(prefab.gameObject, node.pos, instance.sampleList[instance.activeSampleTowerIdx].transform.rotation);//platform.GetRot()*Quaternion.Euler(-90, 0, 0));
    6.  
     
    Last edited: May 28, 2021
    MaxiMaximaal likes this.
  39. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I'm not seeing how I would make a turret to only aim in the built facing direction, with no rotation (similar to Plants vs Zombies linear attack). Is this a public Inspector option or would I need to modify code? If I need to modify, where would I need to look to modify?
    Thanks!
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    There's an attribute 'Targeting FOV' in the TowerEditor that you can set. Setting that to anywhere between 1-359 would limit the tower targeting 'Field of View', forcing it to only fire within the are the it is aiming at. However during runtime, the UI would enable the player to adjust the targeting direction. So to lock the aim direction that you will need to disable that. You can do that by disable 'Allow Target Dir Switch' option on UITowerSelect (you can find it in the scene - TDTK/UI/UICamera/Canvas_TowerSelect/UITowerSelect).
     
    Proto-G likes this.
  41. mhonnibal

    mhonnibal

    Joined:
    Feb 22, 2021
    Posts:
    11
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    It's on the shoot-object. Both shoot and hit SFX.
     
    mhonnibal likes this.
  43. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Excellent! Thanks so much!
     
  44. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Is there an existing way to adjust hit damage and hit chance based on distance from tower.

    Example:
    1) Archer fires arrow at enemy 3 spaces away. Hit damage is 3 and hit chance is 50%.
    2) Archer fires arrow at enemy 1 space away.
    Hit damage is 5 and hit chance is 100%

    Thanks.
     
    MaxiMaximaal likes this.
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Not unless you modify the code I'm afraid. The code in question is AttackInfo() class in UStat.cs, where the hit chance of an attack and the damage done is calculated.
     
    Proto-G likes this.
  46. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Cool. Thank you!
     
  47. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Does this exist in TDTK 4?
    How do I use it?
    Thanks!
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Not really I'm afraid. The way-points on the platform are fixed. Moving the transform in run time won't change the path. The simple way-points without build point though can be manipulated in runtime and the creep will respond to it. But that's only applies when the creep first started to move towards that way-point (the don't update the target way-point position every frame). That said, it can be changed with some simple modification, simply enable line-405 in UnitCreep.cs. There's a comment in the code that explain what that line to code do.

    For future reference, you probably should explain things better than just quote a comment from years ago out of context.
     
    Proto-G likes this.
  49. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I see thanks.

    I assumed it was easy to reference the context, sorry. I'll keep this in mind going forward.

    It looks like this will make all creeps check for, or follow, a moving waypoint.
    If so, how would I go about only having selected creeps in the CreepEditor check for, or follow, the moving waypoint?

    I'm just concerned about it being a performance issue for those creeps that aren't using moving waypoints.

    Thanks!
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You can create an additional bool variable in UnitCreep.cs that when checked, run the code in question. Then you can set that variable to true only for certain creep prefab that you want to follow the moving waypoint.

    Honestly unless you have a lot of creeps active at the same time, or having a lot of big platforms, I doubt it's going to cause any serious performance issue.
     
    Proto-G likes this.