Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

TowerDefense ToolKit 4

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

  1. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Hi Song,

    What do I need to amend in order to change the rotation speed when using Windows? I can't seem to find it in the camera control script.

    Thanks.
     
  2. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    You mean the rotation speed of camera? I'm afraid there's no rotation speed adjustment for mouse input as it's. Something I've overlooked when I write the code. If you want to, you can use the variable 'rotationSpeed' use for touch input. You will need to add the multiplier to line213 and line217. Like so:

    float rotX=deltaX*rotationSpeed+deltaRotX;
    float rotY=deltaY*rotationSpeed+deltaRotY;

    Mind you the variable won't be showing up in the custom editor. You will have to expand the 'show default editor' option to modify it.

    By the way now that you have mention this. I'll add this in the next update. Thanks for pointing this out and sorry for the inconvenience.
     
  3. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Hey Song,

    Thanks for getting back to me and the code works nicely =]. I assumed it would've been an oversight and not intentional.

    Cheers!
     
  4. 047

    047

    Joined:
    Mar 5, 2014
    Posts:
    13
    For the life of me i cant figure out how to use the abilities which requires a target . there must be something that i'm missing !
    should i first click on the ability then the position or the reverse ? although i done both and it didnt work . and i couldnt find any tutorial that in it , someone uses an ability .

    I can use abilities which requires no target like "Super EMP" , but cant use any ability that requires a target like "Shockwave " , frankly i dont even know how to target ! there is no target indicator or something of sort .
    I checked that the terrain has the layer terrain , i even put a quad there with a box collider and assigned the layer " Terrain" to it , still nothing happens and when i click on the Ability icon , uGui shows : " Invalid target for ability " .

    So how should i do it ? thanks
     
  5. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Well, it should be as easy as click on the ability button and click on where you want the ability to be cast on, provided you have the terrain collider setup correctly (which sounds like you have). Have you tried it on the template scene (Tools/TDTK/New Scene)? It should work right out of the box if you use those. If the abilities work in those scene but not in your custom scene, your setup must have gone wrong. It's also possible that you have accidentally turn on 'TouchMode' for UI, making the control only accept touch input. Btw, is there any error shows up on the log or have you make any modification to the UI or code?
     
  6. huxley

    huxley

    Joined:
    Apr 27, 2009
    Posts:
    329
    Hey SOng,

    Is there any option to grey out or hide tower icons in the game selection panel for towers which the player does not currently have enough resources to build?

    Currently, my buildmanager is displaying all towers that I have checked as enabled at start, which works as expected. I would like to grey out or hide the icons which the player does not have enough credits to purchase to make the build options more clear.
     
  7. 047

    047

    Joined:
    Mar 5, 2014
    Posts:
    13
    The abilities wont work in the template scene either . I changed the Build setting to Android before testing anything , could that be the cause of this ?

    Well i still cant get it to work , where can i check to see if i disabled the 'TouchMode' for UI or not ? i checked the UIObject which is parented to the TDTK_FixedPath but couldnt find anything .

    Also when i click on an ability icon in the game window , debug.log shows the name of that ability in the console but uGui shows "Invalid target for ability" . so what could be wrong ?


    EDIT ** I created a new project and imported TDTK , without changing the build setting to android , ( default is windows) now it works ! when i click on an ability it lets me choose a place and doesnt show "invalid target for ability " .
    But ultimately i want to build for android devices and i know it will work for android since i've seen games built with TDTK for android , but how can i adjust editor so i can test skills when build setting is set to Android , since changing to windows everytime i want to develop then changing to android everytime i want to build a test version is a hassle !
     
    Last edited: May 17, 2016
  8. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    @huxley, there's no option for that I'm afraid. The only way to do that would be to modify the UI script, specifically UIBuildButton.cs. The function UpdateActiveBuildButtonList() is called to show/hide what button to display. You can add additional check to to hide any button. One thing to take note is that the function only get called when a build point is selected. In your case, you might want to call the function to refresh the button whenever the player gain resource.

    @047, are you using the latest version of TDTK? Sound like you are since in earlier version, the control only accept touch input when you set the the target build platform to Android or iOS. Also you sholud have the 'TouchMode' option on UIObject if you are using the current version. You should have no such problem if you are using the current version. Btw, you can always play test your Android targeted project that accept touch input only by using UnityRemote.
     
  9. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Hey Song,

    I'm not sure if this has been mentioned in a previous post (I had a quick look on a few pages but couldn't see) but when restarting a scene/level, the ability buttons are visible but no longer work with an error saying:

    I assume this has something to do with the canvas being enabled/disabled when switching between the different end game menus. It is specifically this one line it is pointing to:

    Code (CSharp):
    1. butCancelCanvasG.alpha=flag ? 1 : 0;
    This happens in every scene.

    Thanks.
     
  10. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Thanks for pointing that out. I wasn't aware of it.

    The problem is not with the canvas, but a typing error with the event delegate. In OnDisable(), line101, it should have been

    TDTK.TDTK.onAbilitySelectingTargetE -= OnAbilitySelectingTarget;

    instead of

    TDTK.TDTK.onAbilitySelectingTargetE += OnAbilitySelectingTarget;
    Changing that should fix the issue.
     
  11. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    I made that change and it works as it should now. As ever, thanks for the speedy reply!
     
  12. SignalZak

    SignalZak

    Joined:
    Nov 13, 2014
    Posts:
    12
    I noticed a performance hit when we spawned a zillion (100+) creeps and moved all the update code from Unit and UnitCreep's FixedUpdate into Update (and replaced Time.fixedDeltaTime with Time.deltaTime). Big performance improvement, especially when FPS slows down.

    Is there a reason the update code is in FixedUpdate? FixedUpdate's role is for guaranteeing physics interactions and I saw a lot of things typically found in Update (e.g., hp checks).

    Thanks!
     
  13. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    The reason why some of the code is place in FixedUpdate() instead of Update is to keep a deterministic outcome regardless of framerate. That means the game would always have the same outcome regardless of the actual running framerate. The difference may be unnoticeable when you have a relatively slow game running at 60 fps. However if you have a fast pace game (the creep move very fast for instance) and a relatively low fps (which is often the case on mobile), you will find that similar placement of towers may not give you the similar outcome. This is due to the inaccuracies caused by the undersampling for a slow update rate. By placing those code in FixedUpdate, the actions are being run at a constant rate, thus eliminating any disparity due to undersampling.

    Of course if you are not too bother by the inaccuracies, you can move the code to Update(). It should work just fine.
     
  14. SignalZak

    SignalZak

    Joined:
    Nov 13, 2014
    Posts:
    12
    Great! Thanks for the explanation! Our project doesn't have a need for any fast-forwarding so it makes sense for us to put it into the update.

    I've seen a lot of code in FixedUpdate for no reason in many projects, so I thought I'd check. Thanks again!
     
  15. Almakos

    Almakos

    Joined:
    Dec 13, 2013
    Posts:
    179
    Hey Song,
    I am very interested in your TDTK but can you please clarify a bit about mobile support?
    how does the map navigation work? is FPS mode still available, etc. If you had any examples of games made with your asset and available on mobile for me to play that would be even better.
    Also in the the terrain demo I was not able to place any towers for some reason.
    If mobile integration is all good I'll definitely buy this :)
    Thank you
     
  16. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Well, thanks for your interest.

    Mobile wise, it works pretty much how it's on other platform except for a few difference in control scheme. You can drag the screen to move the map, pinch to zoom, etc (obviously DragNDrop build mode is not really recommend here). FPS mode is available yes. You drag the screen to aim and instead of using keyboard, use on screen button to fire/reload/switch weapon. Unfortunately, I don't have any mobile example readily available.

    There's seems to be a bug in the demo where if you used DragNDrop, you will get some error when you restart or load a new scene. This has been fixed in the latest update.

    Hope this answer your question.
     
    Almakos likes this.
  17. 047

    047

    Joined:
    Mar 5, 2014
    Posts:
    13
    Hello Song
    i got a question , if i'm gonna use 2d sprites as creeps , how can i change the sprite depending on the direction that the creep is walking for a 2d TD game ?
    I mean i want to play "walk left" animation of the creep when are going left or " walk up" animation when they are going up .
    is there a system in place to do this or if there isnt , can you point me to the direction on how to do this plz ?
     
  18. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    I'm afraid there's no such system yet. However it's not too difficult to do. Basically you need to check which direction the creep is moving towards and change the sprite/animation accordingly. Something like this:

    Code (csharp):
    1.  
    2. public SpriteRenderer spRenderer; //the sprite renderer for the unit
    3. public Sprite spriteFrontR;
    4. public Sprite spriteFrontL;
    5. public Sprite spriteBackR;
    6. public Sprite spriteBackL;
    7.  
    8. public void ChangeDirection(Vector3 destination){
    9.    Vector3 pos=thisT.position;
    10.  
    11.    destination.y=0;
    12.    pos.y=0;
    13.  
    14.    Quaternion rot=Quaternion.LookRotation(destination-pos);
    15.    float angle=rot.eulerAngles.y;
    16.  
    17.    if(angle>90 && angle<=180){
    18.      spRenderer.sprite=spriteBackR;
    19.    }
    20.    else if(angle>180 && angle<=270){
    21.      spRenderer.sprite=spriteFrontR;
    22.    }
    23.    else if(angle>270 && angle<=360){
    24.      spRenderer.sprite=spriteFrontL;
    25.    }
    26.    else{
    27.      spRenderer.sprite=spriteBackL;
    28.    }
    29. }
    This is just an example of course, the angle and the sprite direction may not work in your case. You will most likely need to do some tweaking to get the right facing. Maybe even adding more direction if you need more precision. The function is to be called everytime the creep reach a waypoint and change direction.

    Hope this help.
     
  19. jim00

    jim00

    Joined:
    Feb 1, 2015
    Posts:
    42
    I also encounter the same problem where I set up my animation following this link:

    http://www.andrewbrettwatson.com/in...reep-to-tdtk-by-song-tan-for-unity3d-tutorial


    I'm using Unity Standard Assets Characters (Ethan). The animation works fine, but at first Ethan character is moving along the path than, later it just move vary far away from the path.
    And yes i try setting "Dynamic Offset" = 0, still no use.
     
  20. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Dynamic offset give the unit an offset from the intended path. However the offset should be fixed as the unit moves along so it wouldn't move the creep further and further away.

    I guess is that you have the 'ApplyRootMotion' flag enabled in the Animator. Try to have that turn off otherwise the movement of the animation will be applied to the transform itself, shifting it away further and further from it's intended position.
     
  21. jim00

    jim00

    Joined:
    Feb 1, 2015
    Posts:
    42
    great guess! 'ApplyRootMotion'=disable fix the problem. thanks.
     
  22. SignalZak

    SignalZak

    Joined:
    Nov 13, 2014
    Posts:
    12
    Quick perf improvement we made to ObjectPoolManager was to make the activeList a HashSet instead of a List. Then in Pool.Unspawn, you'll want to change the if(activeList.Contains(obj)) block to:
    Code (CSharp):
    1.        if (activeList.Remove(obj))
    2.         {
    3.             obj.SetActive(false);
    4.             obj.transform.parent = ObjectPoolManager.GetOPMTransform();
    5.             inactiveList.Add(obj);
    6.             return true;
    7.         }
    And then in Pool.Clear replace the activeList for loop with:
    Code (CSharp):
    1.        foreach (var activeObj in activeList)
    2.         {
    3.             MonoBehaviour.Destroy(activeObj);
    4.         }
    f

    Accessing items by value in a HashSet is faster than a List, and Remove returns true/false if the object was contained & removed, so you don't need both a Contains and a Remove call. Should improve the Unspawn times (which we noticed with pooled projectiles).
     
  23. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Thanks for the tip!
     
  24. Almakos

    Almakos

    Joined:
    Dec 13, 2013
    Posts:
    179
    yes it does
    forgot to say that I've bought your asset ;)
     
  25. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Thank you. Let me know if you encounter any problem with it.
     
  26. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Is there a way to not allow upgrades per scene/level? I have a tower which I want to be able to upgrade later in the game but not in the first level or so. I can't seem to see anything in the settings unless I have overlooked it.
     
  27. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    13
    Hi Song, first of all I must say that I love the TDTK! I've got a question however, in your documentation you say that animations can be assigned in the editor (TowerEditor in my case) but I can't find where. Am I missing something? I'm trying to set up animations for my towers using the base animations in https://www.assetstore.unity3d.com/en/#!/content/43215

    Also, is there a way to get the AOE tower to only use the EffectObject when an enemy is in range?
     
    Last edited: Jun 9, 2016
  28. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Sorry for the slow respond. The notification system failed me again. :(

    @g0tNoodles, if you are referring to unlocking new tower via PerkManager, you can customize the PerkManager component to show only specific perk item. Disable/Enable specific perk item in specific level so to speak. However if you are referring to direct upgrade from a built tower, there's no such setting. However you can create two identical tower, one with the upgrade and one without. Then in BuildManager, you make those two tower mutually exclusive in each level. In the first few levels where the upgrade is not available, use the one without the upgrade. In the later levels, use the one with the upgrade. Make sense?

    @Drewski66, I'm afraid you cant assigned animation using editor window anyway. It used to be the case in earlier version. However now you can only do it using Inspector. It's fairly straight-forward. Just attach the script UnitAnimation to the prefab and the rest is just the same. You can find the example prefab in TDTK/Animation/ExamplePrefab.

    For the AOETower, you will have to make some code change. It's very simple. Just move line317 of UnitTower to after line324 and add a if(targetList.Count>0) condition. Basically from this:

    Code (csharp):
    1.  
    2.         SpawnEffectObject();
    3.        
    4.          List<Unit> targetList=TDTK.GetUnitInRange(thisT.position, GetRange(), maskTarget);
    5.          for(int i=0; i<targetList.Count; i++){
    6.            AttackInstance attInstance=new AttackInstance(this, targetList[i]);
    7.            attInstance.Process();
    8.            targetList[i].ApplyEffect(attInstance);
    9.          }
    10.  
    to

    Code (csharp):
    1.  
    2.         List<Unit> targetList=TDTK.GetUnitInRange(thisT.position, GetRange(), maskTarget);
    3.          for(int i=0; i<targetList.Count; i++){
    4.            AttackInstance attInstance=new AttackInstance(this, targetList[i]);
    5.            attInstance.Process();
    6.            targetList[i].ApplyEffect(attInstance);
    7.          }
    8.        
    9.          if(targetList.Count>0) SpawnEffectObject();
    10.  
     
  29. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    13
    Thanks a ton Song! Fixed it right up :)
     
  30. UltraTM

    UltraTM

    Joined:
    Dec 8, 2013
    Posts:
    215
    Are there any plans of multiplayer?
    to be able to play like in the good old warcraft 3 times? hehehe
     
  31. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    I'm afraid not. There's no support for multiplayer.
     
    UltraTM likes this.
  32. mahdijj

    mahdijj

    Joined:
    Sep 24, 2015
    Posts:
    31
    in 4 demo scene in your asset i define level ids1,2,3,4then i give next scene name for them in gamecontrol component and enable carry from last scene in levels with id 2,3,4
    i enable "enable save"and"enable load"in perk manager component
    when i play level with id 1 and i win in it and go to next scene resources is carried from last scene, but when i stop run mode and play level with id 2, my resources are 500.
    how i can resolve this problem?

    after this, i want define a perk scene seprate from my levels and in seprate scene,
    i want for example when i finished level 1and 2 and 3 all of perk items that require this level be opened in perk's scene but items that require level 4, not be opened in perk's scene yet

    thanks
     
  33. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Well, the 'carried over' resource value only works for from scene to scene transition in runtime. To have the value persists past that, you will need to save the value. That means a save system of some kind. You can look into PlayerPerf for that. By default, the value is stored in a static variable in ResourceManager when OnGameOver() is called and the value is used again when next level start. So you will need to replace the static variable to a saved value.

    I dont quite get what you mean with the perk scene. You want to displayed certain perks as available but certain perks as unavailable? Have you check the example level "TDTK__PersistentPerk_InterLevel"? That is meant to be a perk menu to be used as independent scene outside a game play scene. The concept of levelID still applies here, you can specify the the levelID in the GameControl component in the scene and the perk item in the perk menu will automatically correspond to that (become available/unavailable).
     
  34. mahdijj

    mahdijj

    Joined:
    Sep 24, 2015
    Posts:
    31
    from where "TDTK__PersistentPerk_InterLevel" gets my last level's id?
    if my game has 4 level and i played until level 2,how perk gets my last level's id(2)?
     
    Last edited: Jun 12, 2016
  35. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Well in that case, you will need to keep a chronological levelID. 0 for level1, 1 for level2, 2 for level3 and so on. Then save the levelID that has been completed if previously saved value is less than the latest value. Once you have this system in place, you can load that leveID and assigned it to the GameControl component in that perk scene.
     
  36. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    13
    DoT effects on abilities and added effects through perks (slow for example) do not work, am I missing something like a check box or is it a bug? Again, gotta say I love the kit
     
  37. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    Let me check and get back to you. If it's a bug I'll get it fixed.

    Please note that this could take me a good few hours since I'm occupied atm.
     
    Drewski66 likes this.
  38. Drewski66

    Drewski66

    Joined:
    Feb 12, 2016
    Posts:
    13
    So I've experimented around with Abilities and what triggers and what doesn't, and I noticed that if I have an effect, lets say slow in this case, AND have a damage value applied then it doesn't do the slow effect, but if I remove the damage then the slow effect will apply. Is that intentional?

    Also, and I apologize if I'm being a pain, I've encountered a strange issue with the RscCreepKilledGain perk giving far too much Resources at the end of a wave if I have it set to give Resources once the wave completes, with the perk off i end the level with 45 Rsc (starting at 0) creeps granting 2 a kill and 25 reward at the end. With the perk on (25% RscCreepKilledGain) i get the correct amount during the wave but once it's done it jumps from around 42~ to 142 and I can't seem to figure out why :(
     
    Last edited: Jun 15, 2016
  39. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    No at all. I should be thanking you for pointing this out. And you are right, I've done some quick testing and indeed there's some bugs. Some perk modifier doesn't get applied. Slow doesn't get applied when there a damage... Anyway, I'll try to fix it asap. Hopefully by tomorrow. Thanks for your patient.
     
    Drewski66 likes this.
  40. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    @Drewski66, I've found and fixed the bug that you mentioned. However it maybe sometime before I update the fix to AssetStore. If you want the it asap, please send me an email so I can send it to you in advance.
     
    Drewski66 likes this.
  41. SignalZak

    SignalZak

    Joined:
    Nov 13, 2014
    Posts:
    12
    We found a bug that occurs when turrets have an extremely high firing rate where the turret gets placed into perpetual cooldown (and can never fire again). Our assumption is that the CooldownRoutine is being called again before the first CooldownRoutine has finished?

    We've fixed it by replacing the CooldownRoutine with a cooldown timer field that gets checked by IsOnCooldown() and reset in Shoot().
     
  42. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    I'm baffled. There is no CooldownRoutine in the code. The whole fire and cooldown tracking is done in a loop in TurretRoutine alone. Could CooldownRoutine be something you added yourself?
     
  43. SignalZak

    SignalZak

    Joined:
    Nov 13, 2014
    Posts:
    12
    We probably have an older version of your code. Sorry about that!
     
  44. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    A psa: I'll be out of office until Friday. Any question/issue will have to wait until then. I thank you in advance for your patient and understanding.
     
  45. boostybleep

    boostybleep

    Joined:
    Nov 20, 2013
    Posts:
    13
    Hi Song,

    I currently have three issues.

    1. I cant get turrets to upgrade. I have tried copying the settings from the included turrets, also upgrading from my turret to an existing turret with no success. I can however upgrade from an included turret to my turret. An interesting point is that the tower highlights but doesnt give options to upgrade etc when clicked on.
    *****FIXED THIS ISSUE*****

    2. Changing some icons in the HUD. While I can change the life and wave icons I cant seem to change the cash icon. In the scene view it shows my new cash icon but when I start the game it changes back to the supplied icon.
    *****FIXED THIS ISSUE*****

    3. Again a HUD issue. I can seem to change the tower descriptions to the font I want. This seems to be happening with text returned from the DB of towers, creeps, perks etc.
    *****FIXED THIS ISSUE*****


    Hopefully you can give me some pointers on these.
     
    Last edited: Jul 18, 2016
    Proto-G likes this.
  46. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    So I take it you solved the 2nd and 3rd issue? Can I know how do you set the upgrade setting from your custom tower? I'm not sure how you 'copy' the setting from the default towers. Fyi you need to do the setting in TowerEditor, under the section 'UpgradeSetting'. You can get more information from page-8 of the documentation.
     
  47. boostybleep

    boostybleep

    Joined:
    Nov 20, 2013
    Posts:
    13

    Hi Song,

    Yes Ive fixed issue 2 and 3.

    Here are the settings for the tower. Its set to upgrade to one of your towers.

    towersettings.png
     
  48. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    I tried a similar setting. It works just fine. Do you have any error message shows up during runtime? Perhaps you can send me your prefab and let me try it on my end.
     
  49. boostybleep

    boostybleep

    Joined:
    Nov 20, 2013
    Posts:
    13
    What email address do I send it ?
     
  50. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,632
    You can find my email in the support and contact window, or in the documentation.
     
unityunity