Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

TowerDefense ToolKit 4

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

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    I can't tell what exactly is the problem without you showing your inspector when selecting the prefab and platform.

    Anyway, I would do it the other way round, placing the prefab as a child transform of the platform. When you do that, make sure the center of the prefab is aligned to the center of the platform (just like how you setup a tower/creep with custom mesh). Then, make sure your prefab (wooden crate) has no collider component on it. Otherwise it could block the click detection on the platform, preventing you from selecting the platform.
     
  2. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    38
    I reversed the object childing and turned off collision for the wood prefab, which resolved the issue thanks :).
     
  3. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    38
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    You need to change the controller in the animator to 'TDUnitController' in TDTK/Animation.
     
  5. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    38
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    You setting seems correct but your animator component is disabled.

    Unfortunately I don't have any other animated character for example. If you want, you can send me your character asset and I'll make an example for you.
     
  7. ceprowler

    ceprowler

    Joined:
    Oct 24, 2020
    Posts:
    18
    The animator is unchecked so it is not being used.
     
  8. AnubisRider

    AnubisRider

    Joined:
    Jul 8, 2013
    Posts:
    3
    So I have a question. What layer name are you using for your particle system? It seems to be missing.
     
  9. AnubisRider

    AnubisRider

    Joined:
    Jul 8, 2013
    Posts:
    3
    Never mind I figured it out. For those of you looking for a answer on this it is. "ParticleSystem" at location 24
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    Sorry about that. Unfortunately there's no way for me to export my layer setting when uploading the package. The particle system for the node indicator is a special use case where the layer is not specified anywhere. For the rest, you can find what layer are used for what in TDTK.cs. Either way you will have to manually configure the layer setting if you want them to show up properly in the Editor.
     
  11. AnubisRider

    AnubisRider

    Joined:
    Jul 8, 2013
    Posts:
    3
    No worries I figured it out. I know how it is with unity. I just noticed that is wasn't on the documentation so I was trying to figure it out but I got it so thank you for the reply means a lot.
     
  12. IvanWeeskey

    IvanWeeskey

    Joined:
    Jan 8, 2017
    Posts:
    11
    Hello,

    I try to expand some tower logic. I've added bool "BlockThePath" to UnitTower.cs. Changed method "UpdatePlatformPath" in Path.cs (screenshot attached). But when I change this value in runtime and call "buildPlatform.UpdatePath(this);" in UnitTower.cs - nothing changing, logic always calculates as there is tower that blocks the path.

    It should change path depending on bool value of "BlockThePath": creeps should go through tower (BlockThePath = false) or should find another path to go (BlockThePath = true).

    Any help appreciate!
    upload_2022-6-8_12-30-11.png
    upload_2022-6-8_12-35-45.png
     

    Attached Files:

  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    It would be much easier if you just do it this way (add the line with the comment):
    Code (CSharp):
    1. public void UpdatePlatformPath(BuildPlatform platform, UnitTower tower=null){
    2.     bool requireUpdate=false;
    3.     for(int i=0; i<wpSecList.Count; i++){
    4.         if(wpSecList[i].platform==platform){
    5.             if(tower!=null){    //if the tower isn't built in the path, there's no need to update the path
    6.                 if(tower.BlockThePath) continue;  //this is the only line you need
    7.              
    8.                 bool inPath=false;
     
  14. IvanWeeskey

    IvanWeeskey

    Joined:
    Jan 8, 2017
    Posts:
    11
    Yes it's easier. But it doesnt help =( When I call buildPlatform.UpdatePath(this); path is not changing. So assume, you place tower with default value of BlockThePath = true. Path is calculated in one way. Then when tower is on the field change value of BlockThePath to opposite and call method buildPlatform.UpdatePath(this); - it will not change the path.
    Looks like method UpdatePlatformPath(BuildPlatform platform, UnitTower tower=null) in Path.cs is cashing something...
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    First off, Sorry I got the condition the other way round. It should be if(!tower.blockPath) continue;.

    I don't know you are calling the function from the tower. I should clarify that UpdatePlatformPath() is intend to for when you build or sell tower. If you call it the way you do, it only works one way, when the tower initially doesn't block the path and then switch to blocking path (this is what happen when you build a tower). When going the other way, you need to pass a null as the tower (Just like selling a tower, there's no more tower). Also you will have to change something in AStar, NodeTD.IsBlocked() to public bool IsBlocked(bool debug=false){ return !walkable || (occupiedTower!=null && !occupiedTower.IsMine() && occupiedTower.blockPath); }. Otherwise any node occupied by a tower is considered blocked by the algorithm.

    Finally, even when calling UpdatePlatformPath() works. The change won't be visible in sceneview as the PathIndicator doesn't update, You need to call TDTK.OnNewTower(this); too. Basically in your tower script, you need this:
    Code (CSharp):
    1. public void UpdatePath(){
    2.     if(BlockThePath) buildPlatform.UpdatePath(this);
    3.     else buildPlatform.UpdatePath(null);
    4.    
    5.     TDTK.OnNewTower(this);
    6. }
    7.  
     
  16. IvanWeeskey

    IvanWeeskey

    Joined:
    Jan 8, 2017
    Posts:
    11
    Thanks a lot! It helps! =)
     
  17. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Can anyone help me with and issue.
    I want to be able to upgrade Perks multiple times.
    The code inside Perk.cs has a value for "repeatable" but i cant find it anywhere in the ui nor is it referenced anywhere.

    I want to be able for the user to upgrade like 20 times 1 skill.

    Like these stats:

    int CurrentLvl,
    int MaxLvl,
    int LvlforNextUpgradeUnlock,
    bool UpgradeAble

    Can anyone help me with this? I tried getting in contact with @songtan but hes MIA atm...
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    I've just responded to your pm.
     
  19. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    I need a way to add more Projecticles to a tower via Perk.
    We have the possibilty to add multiple projectiles to tower so why cant i add more via Perk? Is this a bug or something that will be released in future?
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    I'm pretty sure by default, you can only use 1 projectiles (shoot-object) to each each tower prefab. And there's really no need to have more than 1. As for the perk, I've choose to to focus on things that could actually change the gameplay, the shoot-object are just a visual thing as far as I'm concern.
     
    Niroan likes this.
  21. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    You misunderstood.
    Towers can set the "Target per Attack".
    But this is not available inside the Perk Modifier for Towers.

    2022-08-02_14h01_33.png
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    I see. It's not a bug. It's just one of the things on the tower that are not modifiable by the perk. Not sure if I'm going to implement it in the near future. I've been quite occupied with other stuff.
     
  23. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Can you help me get this to work? :)
    What other projects are you working on now. I tried your TDSTK engine, really to use.
     
  24. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    If anyone wants it i have a working Multiplayer Integration with TDTK4 and PUN2 for live PVP :) Just pm me
     
  25. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    195
    That's impressive. I'm very curious how you handled all the mob and projectile synchronization. I'd be interested if you care to share.
     
    Niroan likes this.
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    The variable in question is targetCountPerAttack in Unit.cs. You can refer to how other stats/properties in the unit.cs are modified during runtime and do the same to targetCountPerAttack. Basically you do that by passing the prefabID of the unit to PerkManager. Of course you will need to add a variable in Perk.cs to support it, and the corresponding function to retrieve the new variable from the target perk in PerkManager.
     
    Niroan likes this.
  27. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    It took a month to build it on TDTK engine. As @songtan said, it would be a mayor undertaking. And boy was i ready to give up many times.

    You need 3 extra Assets to get it working correctly. Mostly for the reason that you dont wanna go and do all the PUN2 settings yourselfs. That is and nightmare.

    First:

    Smooth Sync
    https://assetstore.unity.com/packages/tools/network/smooth-sync-96925

    This asset is essential for everything to be smooth across network.

    DONT USE THIS:
    Code (CSharp):
    1. void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    2.         {
    3.             if (stream.IsWriting)
    4.             {
    5.                 stream.SendNext(transform.position);
    6.                 stream.SendNext(transform.rotation);
    7.             }
    8.             else
    9.             {
    10.                 transform.position = (Vector3)stream.ReceiveNext();
    11.                 transform.rotation = (Quaternion)stream.ReceiveNext();
    12.             }
    13.         }
    But this will make alot of things break, cause you are sending to many calls.
    Smooth Sync is just drag and drop. You simply drop it on every part of your Unit / Tower that does something.
    If the tower turns, then you drag this on it + and Photon View Component. This is descripted inside the tutorial of this asset.

    Second:

    Pure Pool - Object Pooling
    https://assetstore.unity.com/packages/tools/integration/pure-pool-object-pooling-90422

    TDTK engine is amazing, but you need a new pooling engine for PUN2 to work correctly. This is critical for it to work, Pure Pool offers support for PUN2 and have and scripts premade for making network instantiation calls. You dont need to do anything else than changing the way you instantiate creeps and towers.

    And tip that i would wish i new and not spend 2 weeks is everything is opposite of your normal way of thinking.
    Everything inside you game needs to be turn inactive and not enabled for this engine to work. Took me a while to figure out.

    Third:

    PUN 2
    https://assetstore.unity.com/packages/tools/network/pun-2-free-119922#description
     
  28. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    If you have purchased the Pure Pool, i can send you the converted TDTK pooling engine. I just build it on top of @songtan engine so nothing would break. And it works amazing.

    Then everytime the pooling engine normally would call and instantiation of and object, Pure Pool will handle the pooling for both normal gameplay and multiplayer. :) Smooth sync will automaticly sync every object across network.

    You offcause need to turn off some of the syncronization options. As you can see below it got a ton of options to syncronize. You normal creep would like only use position and rotation to something. So you should disable everything else.

    2022-08-03_14h04_00.png
     
    toddkc likes this.
  29. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Many thanks @songtan ! Just direction i needed :)
     
  30. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Is there a easy way to Unpurchase perk?
    I tried to set it _status.Ready and Available. But it does not work...

    Im trying to remove a perk when player click a button.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    It depends on what the perk does. It's not as simple as changing a status of the perk. That only applies to perk that applies changes to tower stats. Perks that add new towers for instance, made the changes when they are purchased, by adding the tower to buildable list in TowerManager. So if you want to 'unpurchase' them, you will have to add the additional code to remove the added tower from TowerManager. Basically you need to check Purchase() in Perks.cs and see what each perk type does and undo what they did when you 'unpurchase' them.
     
    Niroan likes this.
  32. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Its like and earlier user did, you helped him spawn a tower with Ability.
    So the idea is i have a Perk that unlock a tower, but inside the PerkManager, i cant undo the "Purchased" or "Enabled"
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    So here's how purchasing a perk that unlock a tower works. You purchase the perk that unlocks a new tower. The perk status is changed. At the same time, the perk also add a new tower to buildableList in TowerManager. That in turn create a new button for the that tower on the UI.

    Now if you just can change the status of the perk back. But that doesn't remove the tower from the buildableList in TowerManager, and the new button is still there. And that is what I meant, you need additional code to clean that up when you want to undo a perk purchase.

    I don't understand how an ability that spawn a tower has anything to do with this.
     
  34. ceprowler

    ceprowler

    Joined:
    Oct 24, 2020
    Posts:
    18
    Song_Tan, I hope you have been well. I'm trying to add difficulty levels by adjusting the creeps HP. The problem is I'm having a hard time telling which line set the HP when the creeps spawn because there are several variables some dealing with conditional overrides if they are being used and some based on what is assigned to the prefab in the creep editor. Can you point me to the proper script/section? I appreciate it!
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    The place you need to add your custom code is in SpawnManager.SpawnCreep(). Just before the line unitInstance.Init(waveIdx, path). That's where everything has been calculated, whatever you apply to the unit's hp (statsList[0].hp) is the value being used.
     
  36. ceprowler

    ceprowler

    Joined:
    Oct 24, 2020
    Posts:
    18
    Thank you!
     
  37. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Hi @Song_Tan

    Is there a way to center the Main Camera to start node? Like above it?
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    Unfortunately, no. But this should be pretty straightforward to add. You should know where the start node is, so you can just set the 'CameraControl' game-object to that position. This would centre the camera on the start node. If you want the camera to view from top down, then set the rotation x of 'CameraControl' to 90.
     
    Niroan likes this.
  39. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Nice Thanks This worked great!

    another question, mayby solved before.
    When i click a Tower, is it possible to NOT release it on build?

    like if i have 2000 Gold and I select Canon Tower. Then i Can click and build that Tower until i deselect it or run out of Gold.

    i thought it would be 2 places to check but Got lost. Cause there is also a check if i click on somrhting that is not a platform.

    Can you guide me in the right direction. I want to let the user select a Tower. Then when its selected they Can build to their liking. Until Gold run out or deselect happens.

    looking forward for your respons.
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    I don't think this has been done before.

    What you can do is modify the code in TowerManager - Update() where user has click to initiate a build (line-234 in the unmodified script). By default, when a tower is built (after dndTower.Build() is executed), the game exits the 'drag-n-drop' phase. So instead of doing that, you perform a gold check. If there'a enough gold, you can call TowerManager.CreateDragNDropTower() to create another dndTower. Else you proceed with the default code. Make sense?
     
  41. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    Makes sense, allready found it in code now :)
    Is there a place where the "current" selected tower is stored while its being placed?
    So like, i want to show only that tower when its selected and return to normal build UI when user is done building that specific tower.
    I think i need a new UI to make this work, but i just wanna make sure that i dont destroy anything.

    And thanks for super fast reply!
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    You mean the tower being moved around in build phase? It's dndTower in TowerManager.
     
  43. Respaekt

    Respaekt

    Joined:
    Dec 11, 2018
    Posts:
    8
    Iam using a Building Effect for my towers, like a construction animation. Looking for a way to delay the visibility of the tower mesh. Right now when you place the tower, its instantly there and the building effect/animation plays on top/underneath.
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    You'll have to modify the script UnitTower.cs slightly. You can deactivate the mesh object when the tower start building. This is when the building effect get spawned, in Build(). You can activate the mesh object again when the tower has finish building, in Construction().
     
    Respaekt likes this.
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    Which line gives you the error? I just tried exactly the same code and it works as expected.
     
  46. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    I was refering the wrong prefab from the Update() code. It works if i refer to the correct prefab pool :)
    Now i only need a way to NOT add towers unlocked from research/tech tree is there a smart way to disable the UIBuild Buttons being generated? Im going blink looking at the code haha
     
  47. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    105
    @Song_Tan What script is that adds the Unlocked Towers via Perk to UIBuild buttons?
    I strugling to figure this out :)
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    When a perk is unlocked. Perk.Purchase() is called. If it's a 'NewTower' type perk, it will then call TowerManager.AddBuildable(), which in turn called TDTK.OnNewBuildable(), which in fires the event onNewBuildableE, which triggers UIControl.OnNewBuildable(), which then call UIBuildabutton.NewBuildable() to create a build button.

    In short, disable UIControl.OnNewBuildable() to stop the UI from creating a new button without breaking anything else.
     
    Niroan likes this.
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    You must have made some modification to the code. Question is, why your creep is calling PerkManager? The perks are reserved for towers only.

    By default, the perks are designed to allow changes in game. That's why the unit need to keep checking for their corresponding perk modifier/multiplier in runtime. If your perk status doesn't change mid-game. You can modify it so that the units only update its stats just when they are spawned. This way you don't need to call the function in PerkManager every frame.
     
    Niroan likes this.
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,854
    I've sent you a message regarding the issue. Please check your inbox.