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.

TowerDefense ToolKit 4

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

  1. gabrifu01

    gabrifu01

    Joined:
    Jan 16, 2023
    Posts:
    12
    How do I adjust the setting to turn down the sounds of fire in the main menu. so when you turn down the sounds of fire in the main menu, all sections are muted as well. Örnek kod var mı ? . Is there sample code? . or do I need to change the code?
     
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    @darknside, you need to place the object 'circle' under the hierachy of 'Text'. It should goes like this: UI/UICamera/Canvas_Overlay/UIDnDStatusOverlay/Text/Circle. The code moves the object 'Text' to align with the tower. So if you don't do this, the 'Circle' will always stay at where it's.

    As to adjust the radius to above the tower, I don't recommend it. That circle is the actual targeting radius of the tower. What you should do instead is to move the tower sprite in the tower prefab so that when the circle shows up, it's where you want it. If you don understand what I mean, show me the full hierarchy of your prefab and I'll explain.

    @gabrifu01, you can look at the game-object UIPauseScreen and refer to the code in UIPauseScreen.cs.
     
  3. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-2-14_2-16-13.png


    you need to place the object 'circle' under the hierachy of 'Text'. It should goes like this: UI/UICamera/Canvas_Overlay/UIDnDStatusOverlay/Text/Circle. The code moves the object 'Text' to align with the tower. So if you don't do this, the 'Circle' will always stay at where it's.

    upload_2023-2-14_2-16-58.png

    upload_2023-2-14_2-17-11.png

    I did what you said, it didn't work, it's in the wrong place again.
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    I don't see 'Circle' visible in SceneView in your second image. If it's not visible when you can see the text, then it won't be visible at all. I suspect you got the scale or the rotation wrong.

    I'm going to be very honest here and I hope you don't take this the wrong way. What you have been trying to do, and struggling with are mostly beyond the scope of TDTK. While I'm happy to give you general pointer to achieve certain things, it's just not feasible for me to guide you every step along the way. Maybe I'm wrong but I get the impression that you still lack understanding of certain basic aspect of Unity. I suggest you try something simple first instead trying to get something as complex as TDTK to work in the way it's not meant to.
     
    toddkc likes this.
  5. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Just in your Asset a lot of things are not clear, weak documentation because of this you have to ask where the elements are and what is responsible, if you open your script and see the error console in Rider, you will be shocked

    upload_2023-2-14_22-13-48.png

    There's a lot of name-calling and you're afraid to touch anything so your manager doesn't break.
     
  6. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I have to chime in to defend TDTK here. First, I don't think warnings in Rider determine the quality of an asset. Rider is designed to make you adhere to some pretty strict coding standards, and as we all know...you can ignore warnings, errors are the real issue. You used the word "error" in your post, but what you meant was "warning".

    Also, as to the quality of TDTK, I literally taught myself C# by reverse-engineering this asset to work in VR. I know it is overwhelming and frustrating at first, but we all start somewhere. You cannot seriously expect to spend $60 on the asset store and get custom one-on-one consulting to make your game. Honestly if it isn't a bug that causes the asset to not work as advertised you are lucky to get any response. Taking TDTK and making it 2D is just as complex as making it VR, and just like me, you can't seriously expect Song_tan to do that work for you for free? Let's have a little perspective here...
     
  7. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    I guess that's how my translator translated it! Just how do I find the right values in this mess? when everything is reduced for themselves, not for the consumer who buys this Asset, no offense to the developer, here's where I can find for example the radius of placement of towers between each other?

    I ask him questions on his Asset, he frankly blows me away, this offended me, and even Rider almost every method complains that it consumes a lot of resources and burns red
     
  8. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    No worries, I know translation isn't always perfect!

    As to how you find "the right values in this mess", the unfortunate response is you learn C#, and learn this asset well enough that you can find the right values. This asset was designed to easily add and edit towers, for example, but not to change the fundamental ways that towers work within the game.

    As to you being offended, that frankly blows me away. You have already received more time and assistance than you should have ever expected for something that is not a bug causing the asset to not work as advertised. The fact that we have this forum to ask questions and we actually get responses is already above and beyond. Generally you would get some copy/paste response from a customer service person who would have simply told you what you were doing was outside the scope of the asset and good luck. Again, buying this asset in no way entitles you to one-on-one consultation from the developer.

    But really this is none of my business, I just had to chime in and defend TDTK. Good luck with your game, remember nothing about gamedev is easy and we all struggle with things.

    When I was first getting into Unity I bought a popular 3D MMO asset and thought I would easily be able to convert it to 2D....that was quite the reality check.
     
  9. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    I take it this is responsible for the radius between buildings?

    upload_2023-2-15_1-58-3.png
     
    Last edited: Feb 14, 2023
  10. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-2-15_11-5-14.png

    Where can I find the method of this collider?
    I would like to make a radius for it visual
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    I'm not going to claim that the code and documentation are perfect. But with the way it's done, it's perfectly adequate to get your to understand what the framework can do and how to get to work. The framework is designed to do a fixed set of things, within a fixed set of systems. It's not designed for open user modification. That's the limitation I'll admit and unfortunately this is what you are trying to do.

    I'm not trying to start an argument or try to insult you here and I'm very sorry that you are offended by that. I'm just trying to point out what I think is obvious. Take your latest question for instance, I really hope that I've misunderstood the question but it implies that you are not aware of the unity collider system. If I'm wrong, I'm sorry.

    If you are using free-form-mode (on TowerManager), yes that is the radius between the tower use to prevent other tower being built to close to any built tower.

    This is just a default Unity's SphereCollider. It's not from TDTK. I don't understand what do you mean by method.



    @toddkc, Thanks for the kind word. I really appreciate it.
     
    toddkc likes this.
  12. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92

    I use free construction by blocking the construction locations with box colliders, I tried to increase the values of this change radius and it did not bring results! But if I change the size of the collider spheres themselves, the radius changes between towers

    I'm just asking you to tell me where to look so I can make a visual radius of the towers between each other and the places where you can not build, I'm not asking you to write me code or anything! You just tell me and all, and I'll write the code myself

    upload_2023-2-15_13-3-12.png
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    So this is how it works: when you move the tower around in free-form-mode. The code uses Physics.Spherecast() around the tower to detect any collider in the spot, identify them as obstacles to the tower you are trying to place. The 'radius' value you are referring to is use as the range of the Physics.Spherecast(). Now the reason why change collider on the tower prefab affect that spacing is that Physics.Spherecast() is ultimately detecting collider. So if you have other tower in the spot with collider, it will get detected and be treated as obstacle. This is why changing the collider size on the tower prefab affects the spacing between towers.

    To answer your question about the actual radius of the tower. If you are still unsure, it's the 'radius' value that we have been talking. I wasn't refusing to answer your question by the way. You asked in a single post, without additional explanation, a method (?) of a sphere collider so you can display it's radius? Sorry but I just didn't understand it.
     
    Last edited: Feb 15, 2023
  14. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Apparently the DeepL translator doesn't translate my posts correctly, I would like to attach a visual radius to Physics.Spherecast() to make it visible when building, that's why I asked you where it can be done, and how to do it myself, I'm just a newbie and so far I don't understand other people's code where everything is in comments and abbreviations, excuse me. Thank you for continuing to help
     
  15. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    One last bit of advice...if you are using a translator you should probably stop getting so easily offended by what it tells you people are saying. You aren't going to get very far in gamedev without help, and if you constantly get offended by what you think people are saying they probably aren't going to help you.
     
  16. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92

    Who are you anyway? Why do you think I'm constantly offended? Why do you write me something that doesn't make sense?

    Stop creating such off-topic rubbish
     
    toddkc likes this.
  17. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    You specifically made comments stating that. Anyways, you clearly are ignoring my advice. Good luck, I honestly doubt you'll get very far in gamedev or coding in general with the attitude I've seen so far.
     
  18. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    I see you are still writing some nonsense, I think you should not flub.
     
    toddkc likes this.
  19. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-2-16_16-56-21.png

    I got a build radius, now where can I find in your code to block a build if I hit a collider? I want the radius to be red, but I need to create a check, but I don't know what to refer to
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    If you are using free form mode. The code you are looking for is in TowerManager.cs, GetSelectInfo(). Should be in line345 to line352 if you haven't modified the script.
     
    darknside likes this.
  21. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    I could not connect GetSelectInfo() in another script because it is static, tell me what it is for
    public class SelectInfo and can I remove it if I have a free build?
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    Static function means you don't need a reference to a specific instances of the class to call it. So you can just go like this:

    TowerManager.GetSelectInfo(position);

    instead of:

    public TowerManager towerManagerInstance;
    void Update(){
    towerManagerInstance.GetSelectInfo(position);
    }
     
    darknside likes this.
  23. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-2-19_4-39-12.png

    You mean like this?
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    Yes. But there are a few problems. First the function has 3 parameters that you need to pass. And it's not returning a bool so you can't put it in a if condition.

    For what you need, it will be better if you just modify GetSelectInfo() itself. There are a few if-else statement in the function that show if a tower is on a valid build point or not. It's pretty obvious, you can see it's the text 'Invalid build-point'. Just modify the code there to change your sprite indicator.
     
    darknside likes this.
  25. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Thanks for the help, I was already thinking about it today
     
  26. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-2-20_3-23-19.png
    upload_2023-2-20_3-27-48.png
    upload_2023-2-20_3-36-27.png

    I rewrote the scripts to default and now for some reason I can't find these variables

    I feel like I have everything deleted, how can I get the tools etc. back?
     
    Last edited: Feb 20, 2023
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    Clearly you have introduce some error when trying to modify the scripts. Honestly I don't know what you have done. You can't modify TowerManager.cs and break CameraControl.cs. You must have a bunch of compilation errors in your console. What are they?

    I would recommend you create a new project with just clean import of TDTK. Compare with the script in the project with your own to see what faulty modification you have added.
     
    darknside likes this.
  28. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    It just crashed because I moved TowerManager from a clean project and then everything crashed ;(
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    I honestly don't know how to help you here. I don't think modifying TowerManager alone would crash the Editor entirely and I don't know what else you have done.
     
    darknside likes this.
  30. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Where can I find the script responsible for the attack? I want to convert it to a sprite, not a particles
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    The code for attacking is in Unit.cs Attack(). I believe what you are looking for is actually spawning of shootObject. That's in Shoot(), in the same script, just right after Attack() in the script if you scroll down.
     
    darknside likes this.
  32. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-2-23_1-31-37.png

    How can I save them at the player and that they work in different scenes equally? I want to make a perk store on a separate scene of the main menu and that there these data are already transmitted to different levels
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    For the one in the menu, you check the CacheOnComplete so that thing gets cached when player unlock an item.

    For the one in game scene (the levels), you check the LoadFromCache so that it will load the progress cached in the menu.
     
    darknside likes this.
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    You have to keep in mind that the framework works in 3D by default. So the shoot-object is going to aim towards the target as it travels. I suggest you check the option 'straight-projectile' so at shoot-object doesn't change its direction mid-flight. Then you will need to change the corresponding code in ShootObject.cs so that it fix its rotation while traveling towards it's target.
     
  35. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    What method can be used in 2D?
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    I suppose I didn't make it clear enough in my last response. Why your sprite is not visible? Because it's not facing the camera properly. And why is that? Because the default shoot-object code rotate the shoot-object so it faces the target. In your case, you don't want that. You just want the shoot-object to move towards the target, while maintaining its rotation so it face the camera.

    So to answer your question: there's no specific method you should be using here, you just need to change the code to stop the rotation on the shoot-object and have the sprite on the shoot-object always face the camera.
     
    darknside likes this.
  37. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Hi Song!

    If my tower model already has a labeled pivot point (not named TurretPivot), do I need to parent it with an empty gameobject named TurretPivot?

    upload_2023-3-1_6-48-49.png

    The tower is from Vsquad on the asset store.

    Thanks!
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    No. The empty game-object is only needed when you want the mesh/model to pivot at a particular position. If your model has comes with a correct pivot point, then you can just use that one.
     
  39. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Hi, what about in 2d?
    Do I need to rewrite the code?
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    There's coding involved here. Just using an empty transform to shift the turret rotation point. I would say unless you are using top down view, the default rotation (aiming, moving) probably doesn't apply in 2D.
     
  41. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Good morning Song,

    My purchased towers and creeps are a little too big for the scale of the TDTK levels; they are sometimes a bit larger than the squares they are supposed to travel on so they overlap when on adjacent squares.

    If I scale the creeps' prefabs down, their die animation makes them initially scale = 1 (they get bigger for a moment) before scaling them down to die; in this case I will need to adjust the animations.

    What is the correct way of approaching this problem? I just want to ask to avoid doing it wrong the first time, lol.

    Thanks!
     
    Last edited: Mar 4, 2023
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    The animation only control the scale locally. It won't take account of the scale of the parent transform. So what you can do in this case is change the scale of the parent transform and leave the scale of the model at 1. Basically:
    • Create an empty creep prefab with no model (this will be the parent transform).
    • Place the tower and creep model (with animator component on it) as the child transform. Make sure the scale is 1
    • Change the scale of the parent transform until the model fits the level.
    Make sense?
     
  43. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Yes; that makes sense.

    Thanks very much!

    I bet this means I will need to repopulate my Creep database. I will find out lol.

    What should I choose when setting the layer to creep for my creeps (and tower for towers); I had chosen the prefab and changed the layer to creep and got the prompt below.

    Perhaps this should be set on the new parent you mentioned (for the scale problem)?

    upload_2023-3-4_11-26-26.png
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    You only need to set the layer on the parent object. As long as you do that It doesn't matter if you apply to the child objects or not.
     
    darknside likes this.
  45. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Thanks!

    I am unable to replace the prefab in the creep editor; I replace it but it still references the original.

    Do I need to remove and replace each creep that I re-parent (in order to resize)?


    upload_2023-3-4_14-56-18.png
     
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    That's slot is just a reference so you know which prefab you are editing. You cant just outright replace prefab in the CreepEditor (TowerEditor too for that matter). Just add the new prefab as new item and remove the existing item that you don't want.
     
  47. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Can you please tell me where I can find the target that is responsible for Ability in the code?
     
  48. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    RE "target that is responsible for Ability in the code"
    Is this what you are looking for?

    upload_2023-3-4_20-13-37.png
     
    darknside likes this.
  49. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Thanks, I guess this is what I need! But I don't understand what the problem is there, why no targeting of abilities in the 2D game
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    The code doesn't differentiate between 2D and 3D. It just blindly do a ray cast based on the position given and get whatever it has detected as the target. For this reason, you need to set the scene up so that's there's always a target for it. In the default scene, there's a always 'Terrain' object with collider and layer-13 in it. This is for isometric or top down camera. If you are using full 2D with camera angle along horizontal plane, you will need to set up a background object like the 'terrain' object that match the camera angle for this to work.