Search Unity

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,993
    Well, except for the location and name of the controller has been changed, the tutorial still applies. If your prefab still fail to play animation, it could be down to something else. Please send me your prefab via email, I'll be more than happy to help you take a look and make sure it works.
     
  2. JollyManGames

    JollyManGames

    Joined:
    Jul 21, 2014
    Posts:
    10
    Hi Song,
    I have an orbital camera in my scene that I would like to use. The problem is that it seems to be conflicting with the build platforms. When my mouse is over the build platform it does not light up. When my mouse is placed about a centimeter below the platform it lights up. I will attach a picture of the camera. Also when the platform is touching the ground in my scene, I cannot build anything on it.
    Cheers
     

    Attached Files:

  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately your image doesn't tell me much. There are one or two reason why your cursor is out of sync of the platform. First your camera, is it the only game object given the tag 'Main Camera' in the scene. The detection code looks for main camera in the scene using the tag. If some other camera in the scene is given the 'Main Camera', you will get the wrong camera to do the detection and thus detect the wrong thing. Then you have to make sure the collider on the platform object matches the visible grid (if you are using other means to render the visible grid). You can refer to the platform in the example scene to see what I mean. The question is how do you setup your platform and the visible grid. Are you using the default platform and just adjust the scale or you are using other method?

    About the cannot build when platform is on the ground (you mean terrain?). My guess is your terrain has a collider on it and the platform is treating the terrain collider as an obstacle. What you can do is change the layer of your terrain to layer26 (should be named as terrain). Then the platform will ignore the terrain when it perform any obstacle detection.
     
  4. TensonHanzo

    TensonHanzo

    Joined:
    Sep 16, 2012
    Posts:
    13
    Hi Song,
    I placed the code from Start() in Awake() per instructions. Now I'm running into a weird issue where only the 1st two spawned creeps of a specific prefab unit will perform the animation and will only resume animating after de-spawning. I've tried to attached a suitable screenshot to depict this. The circled units are animating, the units that follow are stationary.

    CaptureTDTK.PNG
     
  5. yksmai

    yksmai

    Joined:
    Feb 21, 2016
    Posts:
    3
    @song

    Iam using Unity version 5.3.4 and TDTK version 3.1. In console he tells me that hes missing the canvas group cause it has been destroyed.
     
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @TensonHanzo, Try add this 'animator.Rebind();' to the final line of OnEnable() in UnitAnimation.cs. That should force the animator to reset itself everytime it's spawned, and thus solve the problem.

    @yksmai, I take it you are testing it on the default example scene? Have you do any modification to the code or UI? I'm afraid I can't be too much help here since I no longer keep a copy of 3.1. If there's no reason that you can't update, I would suggest you to update to the latest version 3.1.1.
     
  7. TensonHanzo

    TensonHanzo

    Joined:
    Sep 16, 2012
    Posts:
    13
    Indeed, that did the trick. Thanks!
     
  8. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    21
    Hey Song, I have a quick question. I'm planning on releasing my game on Android, but I'm having issues with TowerView where I'd like to have the upgrade buttons and sell buttons set for touch mode, just like ability buttons are. Like I would like to have those buttons have to be pressed twice, once for selection so the player can see the resource panel without having to hold your finger on it and again to select it. Would that be easy to implement?
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's a good point. I thought I've got everything cover in touch mode. I'll make sure you will need to tap the the sell and upgrade button twice in touch mode for the next update.

    Back to your question, no it shouldn't be too difficult to do. The logic is pretty simple, you create a simple state machine with 3 state(in this case it can be just a simple int), default state, sell, or upgrade. Sell and upgrade state being when sell or upgrade button has been pressed once. When either of the button is clicked, you check for the state. If the state is default, or not equal to their being pressed state, set the state to the button's corresponding state. Else (that means the button has been pressed prior), proceed with the function call and set the state back to default. Hope this make sense to you.
     
  10. yksmai

    yksmai

    Joined:
    Feb 21, 2016
    Posts:
    3
    Okay, i replaced the UIAbilityButton and UIBuildButton script with the new version. Everything fine now.

    Thanks!
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Good to know. :)
     
  12. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    21
    Thanks Song, it makes sense. I'm going through the code for your other buttons to see if I could maybe copy it over lol. Push come to shove I can make my own, thanks again!
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, you can scrap that idea. I've just added that to the code. Send me an email, I'll give you the code and let you know what to do with it.
     
  14. yohami

    yohami

    Joined:
    Apr 19, 2009
    Posts:
    124
    Is it possible to set the grid to half, like Desktop Tower Defense?

     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Of course. The question is, how much work it's going to take. And I'm afraid the answer is quite a lot for what looks like a simple tweak.
     
  16. JollyManGames

    JollyManGames

    Joined:
    Jul 21, 2014
    Posts:
    10

    Hi song,
    I was able to fix the issue by adding the camera that I was using as a child of the camera class in the tower defense toolkit. The only problem is, I can't build the towers. I can drag them and they line up with the building platform, but when I click they disappear. Also instead of a terrain I have a bunch of cubes that make up the terrain. How should I tag these? Thanks for all of your help!
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It's hard to tell why you can't build the tower. Is there any pop up message explaining why? Or is there any message in the console that related to this? Or any error message?

    As for the terrain, it doesn't matter if they are one huge terrain object or made of many cubes. As long as the game objects have collider component on them are not meant to block the platform, they should be layered as 'Terrain'. In short, all those cude should be layered as 'Terrain'.
     
  18. JollyManGames

    JollyManGames

    Joined:
    Jul 21, 2014
    Posts:
    10
    Thank you for the info about the terrain. I cant figure out how to enable tower building. The build platform registers when the mouse is hovering over it, but it doesn't register when I click. Any ideas? Thanks Song!
     
  19. JollyManGames

    JollyManGames

    Joined:
    Jul 21, 2014
    Posts:
    10
    If you have any spare time, I would love it if you could check my project to see if I am doing something small incorrectly.
    Cheers!
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sure. I wouldn't mind. Would be easier for both of us to solve this. You can email me your project.
     
  21. JollyManGames

    JollyManGames

    Joined:
    Jul 21, 2014
    Posts:
    10
    Great! The email is on the way! Look forward to hearing from you,
    Cheers
     
  22. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    21
    Hey Song, I was wondering if I could get your help with something. I have a button that shows a rewarded ad that I want to show on selected waves, my game will be finite waves, like every 5 waves. Currently I have it set like this in UIHUD:
    Code (CSharp):
    1. void OnNewWave(int waveID){
    2.             int totalWaveCount=SpawnManager.GetTotalWaveCount();
    3.             string text=totalWaveCount>0 ? "/"+totalWaveCount : "";
    4.             txtWave.text=waveID+text;
    5.          
    6.             butSpawn.rectT.localPosition=new Vector3(0, 99999, 0);
    7.             if(waveID>0) butSpawn.label.text="Next Wave";
    8.  
    9.             if (waveID > 0) rewardAdButton.SetActive(false);
    10.  
    11.         }
    to turn it off when the wave starts, and:
    Code (CSharp):
    1. void OnEnableSpawn(int waveID)
    2.         {
    3.             int totalWaveCount = SpawnManager.GetTotalWaveCount();
    4.             if(waveID == 5)rewardAdButton.SetActive(true);
    5.         }
    to have it turn on wave 5 for example, but I can't get it to turn on. My coding knowledge is limited so I'm sure I'm making a dumb mistake here lol
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I have one question, what is calling this OnEnableSpawn(int waveID). The original OnEnableSpawn() doesn't accept any argument. Have you created a new function?

    Anyway, the code you are looking for is:

    if(SpawnManager.GetCurrentWaveID()%5==0) rewardAdButton.SetActive(true);

    You can simply add this line anywhere in the original OnEnableSpawn(). The code to disable the button looks fine, in fact you can disable the if(waveID>0) condition.
     
  24. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    21
    Yeah I didn't use my head and just put the arguments in the original OnEnableSpawn lol
    I managed to get it working but it's really sloppy, I'll use your code, thanks a ton Song!
     
  25. mapb2005

    mapb2005

    Joined:
    Aug 31, 2016
    Posts:
    4
    Hey Song!

    I have a couple of questions,
    - How do I edit the Resource list so that I only have 1 kind of resource instead of two?
    - Is there a way to not show the option to go FPS in resource towers?
    - How can I add a reload sound in FPS?
    - I seem to have a problem that when I exit fps the building buttons don't show up :/

    Thank you very much!!! :)
     
    Last edited: Sep 27, 2016
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    To edit the resource, just go to the drop down menu Tool/TDTK/ResourceEditor. You can set add/remove resource you want in your game.

    I'm afraid there's no way to disable an FPS mode for a specific tower as of now. Also there's no way to add a reload sound. I'll try to make that both of that an option in the next update.

    The missing building buttons after exiting is an fps mode is a bug. If you can email me I can send you a fix.

    Edit: There's a way to disable FPS mode for specific tower. It can only be done if you turn on the 'use tower weapon' option in FPSControl and don't assign a weapon to the tower. That also means you won't be able to switch weapon when in FPSMode.
     
    Last edited: Sep 27, 2016
  27. jim00

    jim00

    Joined:
    Feb 1, 2015
    Posts:
    57
    Hi, I have been looking the Main Menu. We can set number of elements correspondence to its scenes (levels). But all the Levels are enable.

    Question, is there a way to enable only the level where user only had won and disable the level where user has not. If yes, how.

    Thanks
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm sorry to say there are not readily available solution with TDTK for that. To do that, you will need to have a save system of some sort to save which level has been cleared, which level is not. Then use that saved data to determined if a level is available or not.
     
  29. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Hey song. Love your engine!

    Just was wondering how I can edit the scripts to make it where all the creeps spawn for that wave at the same time. Or almost the majority spawn at the same time. And offsetting them a little from each other. I cannot find the area to change this :/
     
    Last edited: Oct 7, 2016
  30. jim00

    jim00

    Joined:
    Feb 1, 2015
    Posts:
    57
    Ok, do you mind telling me what function (in which script) that will execute when a level had been won. Thus, I can set a globe variable for passing it to the Main Menu.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Chaz32621, you can look into SpawnManager.cs, specifically SpawnSubWave(). That is the code to spawn all the creeps.

    @jim00, Try GameOver() in GameControl.cs.
     
  32. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199

    @songtan Got it!Thank you!

    I thought it was just for the subwave creeps hahah.
     
    Last edited: Oct 7, 2016
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    There are three ways to approach this as far as I can tell. The easiest one, use random range. Just give it sufficient range and they will most likely be reasonably spread out. However there's no guarantee they won't overlap.

    Second is use a loop to generate a series of position which is evenly spaced out. However this will make them look as if they are queuing up, or forming a square formation.

    The third and the trickiest one is to use random range, but add an additional check to make sure each generated position has a sufficient spacing from each other.

    I would recommend you to got for the first or second method. If you are not too fussy, the first one. If they are too spaced out, just reduce the random value.
     
  34. meliseus

    meliseus

    Joined:
    May 8, 2012
    Posts:
    1
    Hi Song, I've been playing around with TDTK. It's a really capable package but there are features that, I think, would be great additions.

    Creeps spawn "in formation" as shown in the drawing.
    The first formation could be possible with a combination of spawn timing and fixed dynamic offsets on the path.
    The second formation, i think isn't possible with TDTK.
    CreepsSpawn.jpg

    And it could be expanded with 3 or more creeps per line.
    Creep formations, i think, would be a great addition to the capabilities of the package.
    These formation settings could be wave settings.

    Creeps clipping into each other is rather annoying, and prohibits creation of interesting waves combinations
    e.g. a wave of slow moving heavies followed by waves of fast moving creeps, that must pass by them at some point.
    Some sort of avoidance would be really great.

    Path capabilities : The path could have the same entry - exit waypoint.
    The creeps could go from first to last waypoint, and then return through the opposite route.
    This, currently, could be made by adding the same waypoints again to describe the way back, but I think it would be great to have it as a path option.
    An event could be triggered, special animation played etc when they reach the last waypoint and then start on their way back.
    This, of course, would make the creep clipping problem even worse.

    I'll be playing around with the code and come back with any solutions, workarounds.
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your suggestions.

    The thing with formation and avoidance is, they are very complicated to code and apply. It's very difficult to have a single solution that works in all settings supported by TDTK. They are also very computationally expensive as well. Imo it's just not a feasible thing to do.

    Your other point about same entry and exit point for path however is very much doable. I'll consider adding that in the future update.
     
  36. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Hey @songtan

    I was just wondering what could cause my Object Spawn Manager goes back to 0 on a restart?? I modified code a little in some areas. So the first play through of the game everything is fine. Once the player life goes to 0 the game has a panel coming up saying you have lost. The player can hit restart. It recreates the Object Spawn Manager but it never gains any units it has the list at 0. Even when I had a spawn wave amount of 20 on the first go around.
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just to be safe, I would recommend you to just reload the scene when restarting the game. That would automatically reset everything and SpawnManager will start from wave 1 again. But for some reason you can't reload, try change the value of currentWaveID back to -1. You will also need to set the cleared value of every wave in waveList back to false.
     
    Chaz32621 likes this.
  38. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Got it sir. Thanks! Cant wait to get this mobile game out! You will love it! Ive cut some things out and modified the code some but still the core of the spawning is your engine. The TDTK Engine! lol
     
  39. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    @songtan, all the links on your Unity asset store pages download a page to my computer rather than navigating to the demos, or the support forums. Happens on multiple PCs.

    Also, another question. Any plans for gamepad support? or if I was to integrate my own gamepad support, do you have any suggestions on things I will have to deactivate, or change in the core asset?
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks a bunch for pointing out the broken link. I wouldn't have known otherwise.

    I've no plan to add gamepad support I'm afraid. Tower defense is not what you typically play with gamepad. I don't see how would work. But if you want to try that anyway, here are the things you should know.

    The core game mechanic are entirely independent of the UI (input). That means you can remove the current UI script and asset entirely and things will still be fine. So depend on your personal preference, you can start from scratch or just modify the existing UI to work with gamepad. Either way, looking at how the default UI work would definitely help a lot. At least it should give you a good indication of how to interact with the core game code to do certain things (start spawning, build a tower, etc.).
     
  41. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    No problem! It was doing it on all of your assets. I left a comment on your website but didn't see a response there which made me think I should let you know here.

    I'm going to mess around with integrating gamepad support. The controls I want to achieve are much like the free game Battle Island on PS4. single cursor in the
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's strange. I certainly didn't see any of new comment that I haven't respond to (I have just checked).

    Anyway, good luck with the gamepad integration.
     
  43. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Hey @songtan

    Quick problem.

    Trying to grab all the unit creeps in a small area. Which is based off a touch from the player.

    I keep getting an error: NullReferenceException: Object reference not set to an instance of an object.

    Ive have tried so many other ways of doing this but I cant get it here is the code.

    Code (CSharp):
    1.  public void ActivatePickupSpell(Vector3 pos, float rad, int AbilityID, Unit tgtUnit = null)
    2.         {
    3.          
    4.             if (AbilityID == 0)
    5.             {
    6.                 List<Unit> creepList = new List<Unit>();
    7.                 PickupSpellIndicator.transform.position = new Vector3(pos.x, pos.y, pos.z);
    8.                 PickupSpellIndicator.localScale = new Vector3(1.5f, 1.5f, 1.5f);
    9.                 Instantiate(PickupAbi[0], pos, Quaternion.Euler(new Vector3(0, 0, 0)));
    10.                 Collider[] hitColliders = Physics.OverlapSphere(pos, rad);
    11.                 if (hitColliders.Length > 0)
    12.                 {
    13.                     for (int i = 0; i < hitColliders.Length; i++)
    14.                     {
    15.                         creepList.Add(hitColliders[i].gameObject.GetComponent<UnitCreep>());
    16.                         for (int n = 0; n < creepList.Count; n++)
    17.                         {
    18.                             creepList[n].ApplyDamage(Random.Range(SpawnManager.currentWaveID * 1, SpawnManager.currentWaveID * 2));
    19.                         }
    20.                     }
    21.                 }
    22.             }
    23.             if (AbilityID == 1)
    24.             {
    25.                 List<Unit> creepList = new List<Unit>();
    26.                 PickupSpellIndicator.transform.position = new Vector3(pos.x, pos.y, pos.z);
    27.                 PickupSpellIndicator.localScale = new Vector3(2f, 2f, 2f);
    28.                 Instantiate(PickupAbi[1], pos, Quaternion.Euler(new Vector3(0, 0, 0)));
    29.                 Collider[] hitColliders = Physics.OverlapSphere(pos, rad);
    30.                 if (hitColliders.Length > 0)
    31.                 {
    32.                     for (int i = 0; i < hitColliders.Length; i++)
    33.                     {
    34.                         creepList.Add(hitColliders[i].gameObject.GetComponent<UnitCreep>());
    35.                         for (int n = 0; n < creepList.Count; n++)
    36.                         {
    37.                             creepList[n].ApplyDamage(Random.Range(SpawnManager.currentWaveID * 2, SpawnManager.currentWaveID * 5));
    38.                         }
    39.                     }
    40.                 }
    41.             }
    42.          
    43.         }
    What am i doing wrong? It is not getting the creeps in the area very well??
     
    Last edited: Oct 25, 2016
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You haven't told me where the error comes from so I'm going to take a guess. The most likely suspect is you are using OverlapSphere without any layer-mask. That means it will pick up any collider in range, including the non-creep object (platform for instance). So you end up getting null when you use GetComponent on those collider object.

    To solve this, you can either use a mask for the OverlapSphere, or perform a if(creepList[n]!=null) check before you call ApplyDamage.
     
    Chaz32621 likes this.
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick note that the latest update has just gone live.

    Nothing major, just a bunch of small fixes and some small additions. :)
     
  46. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Hey Song, hope everything is going well. I'm trying to modify scripts from being based on mouse/cursor to being based on raycast from various cameras in world space. Would you be able to assist with this? I have all the UI stuff working, just need the tower building functioning. Right now it's ray casting and working, but from an odd angle on my main camera (which is an HMD) Here's an example of what i think needs to be modified: Ray ray = mainCam.ScreenPointToRay(pointer); Instead of ScreenPointToRay I just need simple raycast forward from camera :)
     
    Last edited: Nov 3, 2016
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm sorry but I'm afraid your example is not clear to me. if cursor is not used, what is the pointer stands for? Maybe you mean you want to cast in the forward direction of the camera transform? In that case, try this - Physics.Raycast(camera.transform.position, camera.transform.forward)
     
  48. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Sorry, what script contains the code for the camera that moves the build indicator around and makes the TowerView UI appear when looking at an already built turret?
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The code the code that show the indicator is in BuildManager.cs SetTileIndicator(). The code that detect user input and show the UI is in UIMainControl.cs OnCursorDown().
     
  50. a548922

    a548922

    Joined:
    Nov 5, 2016
    Posts:
    9
    I was wondering how to change it so that it can recognize targets below the tower. For instance if the tower where elevated with a longer range, how do I tweak it so that it detects the units below the towers sight line?

    Thanks.