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
    Yes it can. The mechanic should work just fine, 2D or 3D. The problem is it doesnt support sprite animation so you will have to find a way around that.
     
  2. Whispy

    Whispy

    Joined:
    May 10, 2014
    Posts:
    8
    Hi, total noob here.
    I just purchased and downloaded this.
    Where can I find the step by step documentation?
    Thanks.
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase. You can find the pdf documentation in the package. Alternatively there's a series of quick video toturial here - http://www.youtube.com/playlist?list=PLGVG8RbKurZI_yumEpziPMOlOuDQbC6NJ

    The video are a bit out-dated but it should give you a good idea of what to do and where to start. If there are stuff that are unexplained or different in the video to the current version, chance are you will them comes with tooltip or made a lot more intuitive.
     
  4. alvinlim

    alvinlim

    Joined:
    Jun 18, 2013
    Posts:
    4
    Hi songtan. I notice that the UI is too small when build into Android (Kitkat 4.4). I created one scene Mazing (Default UI) with two waves and use existing 3D models. When export to Android device Samsung Galaxy Note 3, the buttons, scores, text and towers selections are too small to be seen. The grid platform is okay because it can be zoom in but buttons and text are fixed size.

    May I know how to change the button size to match with device screen size automatically? I am total newbie in Unity too. TowerDefenseToolkit is a helpful kit for newbie like me. Thanks

    EDIT: I tried to build run the example scene on another device (JellyBean 4.3). The result is same also.
     
    Last edited: May 13, 2014
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid that is an inherent problem with the default Unity UI on modern mobile device. The problem is they all have relatively high screen resolution, but is squash down to a very small physical size. Also if I remember correctly (I might be wrong here), the text size cant be change on mobile if you are using default UI. At least you can change the size of the button and boxes. Unfortunately the way the UI is coded there's no way to doing this automatically. If you are using NGUI, there might be a way to get arround it. Or at least you can visually adjust the size of the UI in Unity Editor. Since you are using default UI, I'm afraid you can only do so via code in UI.cs. It's quite a time consuming task if I'm honest.

    For mobile device, I would strongly recommend you to consider using NGUI. It's much more easy to work with and much less taxing on the performance
     
  6. alvinlim

    alvinlim

    Joined:
    Jun 18, 2013
    Posts:
    4
    Thank you for your quick reply and help, songtan :) I will consider using NGUI for mobile device then.
     
  7. Mike237548

    Mike237548

    Joined:
    Mar 23, 2013
    Posts:
    5
    Hello, great asset! I am hoping you can help me.. i cant seem to get all of the demo scenes listed in the menu to build. The build menu looks like it is looking for scenes in TDTK_v2.5.5/ and i dont seem to have these files, i do however have the scenes under TDTK/TDTK (base)/ExampleScenes.

    Thank you for your help,
    ~Michael
     
  8. Mike237548

    Mike237548

    Joined:
    Mar 23, 2013
    Posts:
    5
    i renamed the scenes accordingly.. problem solved, thank you anyway!
     
  9. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    219
    Hello,
    Really nice asset, is there a way to make the grid bigger to place big towers ?
    Also a tutorial on how to setup the towers and enemeies (i meant the towers and enemies prefab itself not adding them to the tower manager)

    Thanks
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thank you!

    For the gridSize, just change the GridSize value in BuildManager.

    For tutorial how to setup towers and enemies, try go through video 4 and 5 on this list. If you havent already, I would suggest you go though all of them. Most of them should be pretty helpful if you are not familiar with how things work. Just a note, setting up towers and creep can be as easy as snap the UnitTower.cs or UnitCreep.cs on the gameObject.

    Hope this help.
     
  11. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    219
    Hi,
    Ok i will try that thank you :)
     
  12. BurningthumbStudios

    BurningthumbStudios

    Joined:
    Apr 28, 2008
    Posts:
    95
    Hi,

    I'm using the Free NGU but if I try to use the pie menu its offset to the right. I have attached a picture. Any ideas why this happens?

    $Screen Shot 2014-05-22 at 9.02.21 PM.png
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Check the position of BuildPanel Transform, make sure it's (0, 0, 0). If that doesnt help. Please let me know
     
  14. weishoongteh

    weishoongteh

    Joined:
    Aug 22, 2013
    Posts:
    1
    Belated thanks from your satisfied customer from about 1/2+ year ago. We are thrilled to share with fellow indies and fellow users of TDTK that "Defenders of Time" from Four-Lights.com a highly cooperative/head to head online TD ( using TDTK ) has scrapped our way to show to the public at E3 (Los Angeles) this year, at South Hall booth #2447 ( between Disney Interactive and Warner Brothers ).
     
  15. BurningthumbStudios

    BurningthumbStudios

    Joined:
    Apr 28, 2008
    Posts:
    95
    Yup that fixed it.

    Maybe in a future update, in addition to the Use Pie Menu checkbox you could include a vector3 position for the pie menu so that the transform position doesn't need to be changed. It could be more obvious, so like:

    Use Pie Menu [ ]
    Pie Menu Position [ x ] [ y ] [ z ]
     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @weishoongteh, perhaps a link to show us your game? :)

    @BurningThumb, noted. I'll see what I can do.
     
  17. BurningthumbStudios

    BurningthumbStudios

    Joined:
    Apr 28, 2008
    Posts:
    95
    I have a new issue with the BuildToolTip. The Pie of towers shows up but when I mouse over a tower there is no tool tip. It seems to be 2 issues really, first is the position of the BuildToolTip Transform, I guess similar to the position of the BuildPanel, but it seems I need to set the BuildToolTip Transform to a very odd value of: -380, -155, 0 (I found it on the AbilityToolTip).

    Is this the correct way to position to BuildToolTip for pieMenu?

    Second it does not seem to activate. I looked at the UInGUI.cs script and in the method OnTowerTooltip, there is code:
    Code (csharp):
    1. //activate the tooltip so it's visible
    2. Utility.SetActive(buildTooltip.rootObj, true);
    It seems to not activate the tool tip children. Maybe something else is controlling what parts of the toolTip are active. I know I can make it work by adding this line of code:
    Code (csharp):
    1. buildTooltip.rootObj.SetActiveRecursively(true);
    But surely this is not the correct way to do it. Can you tell me what is controlling the visibility (and position from above) of the buildTooltip ?

    Edit:

    I looked a bit more and it seems maybe the answer lies in the method OnClearTowerTooltip. It has a line:
    Code (csharp):
    1. #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    If I change that line to:
    Code (csharp):
    1. #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3
    Now the tooltips do show up as well and it seems better than the previous line. So maybe it is a bug after all that affects Unity v4.3 only?

    The complete method becomes:
    Code (csharp):
    1.     //function call to clear tooltip, called when the mouse is moved out of a button
    2.     void OnClearTowerTooltip(){
    3.         #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3
    4.             if(buildTooltip.rootObj.activeInHierarchy){
    5.                 buildTooltip.rootObj.SetActive(false);
    6.                 if(buildMode==_BuildMode.PointNBuild  showBuildSample) BuildManager.ClearSampleTower();
    7.             }
    8.         #else
    9.             if(buildTooltip.rootObj.active){
    10.                 buildTooltip.rootObj.SetActiveRecursively(false);
    11.                 if(buildMode==_BuildMode.PointNBuild  showBuildSample) BuildManager.ClearSampleTower();
    12.             }
    13.         #endif
    14.     }
    Edit 2:
    If this is the issue, there are many other places where the code:
    Code (csharp):
    1. #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    Appears and it could mean many Unity 4.3 bugs ?

    grep -R UNITY_4_2 *
    BuildManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    BuildManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    BuildManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    MiniMap.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    MiniMap.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    ObjectPoolManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    ObjectPoolManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    ObjectPoolManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    ObjectPoolManager.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    PathIndicator.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitCreepAttack.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitCreepAttack.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitCreepAttack.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    UnitTower.cs: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2

    Should I change all these lines of code ?
     
    Last edited: May 23, 2014
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The way build tooltip intend to work is that it will show up at a position relative to the build button. The relative position is taken from where the tooltip transform is placed relatively to the initial template build button before the game start.

    Nothing is wrong actually, it's just some issue with anchoring of the transform. What actually happen in your case is, the default ngui prefab has it build button set to the middle of the screen. I made a careless mistake to move the parent of the build button (the one which you have set to (0, 0, 0)) instead of moving the build button itself. So this mess up the pie menu anchoring. Now that you have reset the parent position, and build button is moved in the process, thus changed the relative position between the tooltip and build button.

    As for the activation issue, I'm not really sure what happen there. The reason I used a wrapper function is TDTK is still being supported on Unity3.5, which doesnt use SetActiveRecursively. If you look into the function itself, it's actually running buildTooltip.rootObj.SetActiveRecursively(true); if you are using Unity4.0 and above. At any rate, it seems to be a bug. Let me look into and I'll get back to you.
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    whoa, I didnt see your edit before the last post.

    You are right, the missing UNITY_4_3 is causing the problem. It would probably be better if you just change the function to this:
    Code (csharp):
    1.  
    2.     void OnClearTowerTooltip(){
    3.         #if UNITY_3_5 || UNITY_3_4
    4.             if(buildTooltip.rootObj.active){
    5.                 buildTooltip.rootObj.SetActiveRecursively(false);
    6.                 if(buildMode==_BuildMode.PointNBuild  showBuildSample) BuildManager.ClearSampleTower();
    7.             }
    8.         #else
    9.             if(buildTooltip.rootObj.activeInHierarchy){
    10.                 buildTooltip.rootObj.SetActive(false);
    11.                 if(buildMode==_BuildMode.PointNBuild  showBuildSample) BuildManager.ClearSampleTower();
    12.             }
    13.         #endif
    14.     }
    15.  
    Btw, thanks a bunch for the detail listing. Feel free to do the change to other script which contain the error. I'll do that and put it on hte next update.
     
    Last edited: May 23, 2014
  20. BurningthumbStudios

    BurningthumbStudios

    Joined:
    Apr 28, 2008
    Posts:
    95
    I think I will just change:

    Code (csharp):
    1. #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
    to:

    Code (csharp):
    1. #if !UNITY_3_4  !UNITY_3_5
    It should work everywhere and I don't need to change the code order. For sure it will work for me since I'm always using the latest version of Unity.

    Thanks for looking at it and I look forward to the next update.
     
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick note that I will be on the move starting 26thMay until 13thJune so apologize in advance if I don't respond to any post in a timely manner.
     
    Last edited: May 25, 2014
  22. danishwaseem

    danishwaseem

    Joined:
    Apr 11, 2014
    Posts:
    1
    Can I use TDTK to make a 2D game?
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Mechanically yes, it should be good for 3D as well as 2D. But when comes to visual, it depends. If the game is just a top down 2D game with no sprite animation, yes, definitely. However, if the game require isometric 2D setup and require sprite animation and what not, you will probably have to add some modification of your own to get the sprite animation works correctly.
     
  24. BurningthumbStudios

    BurningthumbStudios

    Joined:
    Apr 28, 2008
    Posts:
    95
    Hi Song,

    I'm a bit confused by the Unit Creep shoot point.

    There is a simple array on the UnitCreep script called ShootPoint, but there is also a TurretObject which in turn can include an array of shoot points.

    The script looks like its using the TurretObject and not the simple ShootPoint array. But I'm not sure if its supposed to be using the simple shoot point array if the creep has no turret object (in such case its a bug in the else clause). The method of interest is:

    Code (csharp):
    1.     private void UpdateShootPointNBarrelObj(){
    2.         //get shootpoint, assigned to TurretObject component on turretObject
    3.         if(turretObject!=null){
    4.             TurretObject turretObj=turretObject.gameObject.GetComponent<TurretObject>();
    5.             if(turretObj!=null){
    6.                 barrelObject=turretObj.barrelPivotPoint;
    7.                 //make sure the shootpoint is not null
    8.                 if(turretObj.shootPoint!=null  turretObj.shootPoint.Length>0){
    9.                     shootPoint=turretObj.shootPoint;
    10.                     return;
    11.                 }
    12.             }
    13.             else{
    14.                 barrelObject=null;
    15.                 //no specify shootpoint, use turretObject itself
    16.                 shootPoint=new Transform[1];
    17.                 shootPoint[0]=turretObject;
    18.                 return;
    19.             }
    20.         }
    21.        
    22.         //this tower have no turretObject, use thisT as shootPoint
    23.         shootPoint=new Transform[1];
    24.         shootPoint[0]=unit.thisT;
    25.         return;
    26.     }
    27.  
    Can you confirm if the ShootPoint array on the Creep is not to be used and instead the Creep should have a Turret Object that includes the shoot points or is this a bug in the UnitCreep? Its a bit confusing so any light you can shed on how its supposed to work would be good.
     
  25. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    There's no bug there. Everything is working as intended. But on a hindsight I should have made the shootPoint array on the UnitCreepAttack component private. You see it's the same as how Turret and shootPoint in Towers work. You assign a TurretObject component on the turret, then assign the shootPoint on the TurretObject component. In runtime, the function you shows me will look for the TurretObject component and set the shootPoint on the UnitCreepAttack instance to those in TurretObject. So basically, whatever shootPoint you assign to TurretObject will be used as the shootPoint for UnitCreepAttack. That is unless there's no TurretObject assigned to the UnitCreepAttack component or any shootPoint is assigned to TurretObject component. If that's the case, the creep transfrom itself will be set as the shootPoint. Keep in mind that at lease one shootPoint will be required in order to spawn any shootObject.
     
  26. EasyPlay

    EasyPlay

    Joined:
    Mar 23, 2014
    Posts:
    8
    It is very good,But I want to use 2D art ,not 3D model,Can I use it ?
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Art asset is not a factor at all for the kit as far as the game mechanic concern. It can works with both 2D and 3D asset. The limitation with 2D art is that the kit doesnt support sprite animation by default. So while you can use 2D art, you may not be able to animate it without any modification. But you should be perfectly fine as long as your game doest require sprite animation.
     
  28. BurningthumbStudios

    BurningthumbStudios

    Joined:
    Apr 28, 2008
    Posts:
    95
    That was one of the things I considered. I'll change it to private to remind myself not to use it.
     
  29. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    Any way you can add support to handle 2D sprite animation using Unity's Sprite system?
     
  30. EasyPlay

    EasyPlay

    Joined:
    Mar 23, 2014
    Posts:
    8
    thanks,I want to use 2dtoolkit sprite animation。I think if you support 2D and animation,that will be great.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Saxi @EasyPlay, Have to say adding support to sprite animation is not a trivial task. And I'm afraid I dont really have a lot of time on my hand to look at the possibility for the foreseeable future. Perhaps in couple months down the line, I will see if there's anything I can do about it, if I got the time. But there's no promise here. I hope you understand.
     
  32. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    Song, why don't you make a RPG kit? something like that you have done with TDTK?
    I'm one of your TDTK's customer and I would love to have RPG kit that is made by you!
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    As much as I wish to, making a kit with quality on par with TDTK is not easy. If I dont think I can make a tool that is useful by my own standard I rather not make it. And to be perfectly honest, cost efficienccy of the effort required is part of my consideration. I'm afraid I have to weigh that in with my limited time and resources. It's great fun trying my hand on different stuff and Ideally I would like to have a toolkit for each for each major genre. Unfortunately the it's not viable most of the time. Maybe one day I'll have the luxury to sit down and try my hand on it, but for now I have not plans for it.

    Anyway there are quite a few of decent RPG kit out there, perhaps you can check them out.
     
  34. DOTEngineer

    DOTEngineer

    Joined:
    Jun 14, 2014
    Posts:
    1
    Hi TDTK community, following up on Song's request for Pictures from our may23rd post. Finally recovered from our crazy effort to get our game "The Defenders Of Time" to E3, showing it live there and returning safely. We are very fortunate to have better than pictures! Please see this video link and demo featured on GameSpot. http://www.gamespot.com/videos/e3-2014-defenders-of-time/2300-6419613/. (Gameplay video starts around 5 minute mark) Our website ( still in development ) is at www.TheDefendersOfTime.com for more info. Thanks Song and TDTK !
     
    Song_Tan likes this.
  35. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    congratulation, looks great. Are you planing make it for mobile?
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Congratulation indeed! Very impressive stuff. All the best in your future effort!
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick note that a new update (v2.2.5f4) has just gone live on AssetStore. Not much of an update really, the changes and fixes are as follow:

    new addition

    • tower upgrade now support replacement of an netire tower using new tower prefab

    bug fix
    • when using accumulating resource, carried over will no longer be added on when restarting scene.
    • fixed a few bugs with NGUI-free
    • fix a bunch of version related issue, deprecated code should no longer throw up warning in later version of Unity Editor.
     
  38. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    I just updated to the latest v2.2.5f4 version and got this error:

    Internal compiler error. See the console log for more information. output was:BCE0042: Error reading from 'Assets/TDTK/TDTK (Base)/FPSDisplay/FrameRate.js': 'Could not find a part of the path "/Users/XXX/Documents/Unity Project/Assets/TDTK/TDTK (Base)/FPSDisplay/FrameRate.js".'.

    BTW....I am still on Unity 3.5.7.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have to say I've never come across something like this before. Fyi I'm using Unity3.5 myself and I haven't change anything about the script in question since the first release. So if the problem shouldnt be coming from the content of the script itself. It's more likely to do with the setting of the particular file on the hard disk.

    Have you try delete the file and re-import or simply re-import?
     
  40. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574

    Weird. I just restore (Apple Time Machine) to the previous version, then instead of delete the file as before, I simply update it and it throws no error. :)
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Problem fixed.. ?

    I suppose it's just one of those weird instance. :)
     
  42. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574



    Got another weird one. If I try to select "FrameRate" Unity will give me this error endlessly. Its no biggie really because that's not a file (the "FrameRate" below that is the real script file) but its just a weird bug.
     
  43. canibecooltoo

    canibecooltoo

    Joined:
    May 13, 2014
    Posts:
    29
    U plan on add a save system for the upgrades and levels as the player beat each level?
     
  44. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    hi Song, something conflict with NGUI after remove Free version and import NGUI 3.6.4

    Assets/TDTK/Scripts/C#/UI/UIRect.cs(5,14): error CS0101: The namespace `global::' already contains a definition for `UIRect'
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond guys. For some reason Unity forum has reset all my watched thread so I'm not getting any notification.

    @I am da bawss, Seems to me the file is corrupted, some how. If the original file is still intact and working, you can delete the one that cause the error, I dont think it's in use.

    @canibecooltoo, I dont have any plan for that for the time being. The way the level/scene can be organised in Unity, I think a save system is best implemented by the user as they see fit.

    @Gunhi, the NGUI version meant to be support for TDTK is 3.7 and up. You are using 3.6 hence the error.
     
  46. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    oh, it works now! thanks Song
     
  47. seidgaparov

    seidgaparov

    Joined:
    Jul 18, 2013
    Posts:
    18
    1)How can i do simple interaction for creeps, FIND-AND-ATTACK towers?
    2)how to turn on attacking mode for creeps?
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    If you just open CreepEditor, on the right column there's a line Attack/Support Unit with a button "Add Com". Just press that and you should be able to set the creep to an attacking unit. You will have to setup the various attacking properties tho. You can refer to the example creep, a few of them are setup to attack towers.
     
  49. seidgaparov

    seidgaparov

    Joined:
    Jul 18, 2013
    Posts:
    18
    Wanted to add some variables to Towers, like unit they(tower) will spawn and spawn cooldown, and to add them in TowerEditor:


    Did some code addings:
    in UnitTower.cs
    Code (csharp):
    1. private GameObject SpawnUnit;
    2. private float SpawnCooldown;
    in TowerEditor.cs
    Code (csharp):
    1. EditorGUI.LabelField(new Rect(startX, startY+spaceY, 200, height), "SpawnUnit: ");
    2. tower.upgradeStat[i].SpawnUnit=(Transform)EditorGUI.ObjectField(new Rect(startX+lW-30, startY+=spaceY, 100, height-2), tower.upgradeStat[i].baseObject, typeof(Transform), false);
    3.                                    
    4. EditorGUI.LabelField(new Rect(startX, startY+spaceY, 200, height), "Spawn CD: ");
    5. tower.upgradeStat[i].SpawnCooldown=(Transform)EditorGUI.FloatField(new Rect(startX+lW-30, startY+=spaceY, 100, height-2), tower.upgradeStat[i].baseObject, typeof(Transform), false);


    Unity gave me error:
    Error: Assets/TDTK/TDTK (Base)/Scripts/C#/Editor/TowerEditor.cs(755,94): error CS1061: Type `TowerStat' does not contain a definition for `SpawnUnit' and no extension method `SpawnUnit' of type `TowerStat' could be found (are you missing a using directive or an assembly reference?)

    Where i should add code and what should i add?
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid it's not as simple as you imagine. The way it work is all the stat are of a class TowerStat. Each level of tower has it's own corresponding TowerStat, all store in a list. Then the tower has it's own local variables mirroring each variables in the TowerStat class. These would store the value of the TowerStat's variable currently in used.

    So if the new variable you want to use is constant across different level, you dont need to put it as a member of TowerStat. Otherwise you need to extend the TowerStat to accomodate the new variable. When upgrading the tower, you will need to copy the value used in the corresponding TowerStat to the local variable.

    The easy way out for you would be to use constant value for all level of the tower. Assuming that's the case, then you need to remove upgradeStat in those line in TowerEditor.cs. Like so:

    Code (csharp):
    1. EditorGUI.LabelField(new Rect(startX, startY+spaceY, 200, height), "SpawnUnit: ");
    2. tower.SpawnUnit=(GameObject)EditorGUI.ObjectField(new Rect(startX+lW-30, startY+=spaceY, 100, height-2), tower.SpawnUnit, typeof(GameObject), false);
    3.  
    4. EditorGUI.LabelField(new Rect(startX, startY+spaceY, 200, height), "Spawn CD: ");
    5. tower.SpawnCooldown=EditorGUI.FloatField(new Rect(startX+lW-30, startY+=spaceY, 100, height-2), tower.SpawnCooldown);

    Please note that you have quite a few of syntax errors in your code. You need to change the passing argument to the editor function call as well to what the variable you are trying to edit. Finally not sure where you place these two lines of code in your script, but you might not want to put that in the editing upgrade stats section