Search Unity

TowerDefense ToolKit 4

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

  1. Budgieboy

    Budgieboy

    Joined:
    Sep 6, 2012
    Posts:
    40
    Ah ok, thank you songtan.

    I disabled UI and only had the ios UI but the screen was blank when running in unity, do I have to build the game for it to work?

    Edit: Seems it still won't work.

    I tried changing Unity's UI skin by creating a GUI Skin but it's not changing anything.
     
    Last edited: Sep 26, 2012
  2. Budgieboy

    Budgieboy

    Joined:
    Sep 6, 2012
    Posts:
    40
    Please help I don't want Unity's default GUI style.
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Very sorry I missed your post yesterday.

    What do you mean "the screen went blank"? Is the whole gameview not showing anything or just all the UI is missing? Were you using the example scene? You dont need to build the game for UIiOS to work. It should work just fine in Unity Editor. Any error message on the log? Actually you can try all example scenes. I've set them up so that they cover all the UI available. So you can use the one you want as template, make sure it works and move from there.

    When you create a new unity GUI skin. It's still pretty much the default skin. You have to change various element on the skin via the inspector to make a difference. Check this out. Also please make sure you have assing that new GUI skin to the variable skin on script UI.

    Edit: Sorry I just realise the UI doesnt have the facility to use custom skin. I remember I've added that sometime ago but apparently I didnt. Please change the code in UI.cs, in line 325 from:
    Code (csharp):
    1.  
    2. void OnGUI(){
    to

    Code (csharp):
    1. public GUISkin skin;
    2. void OnGUI(){
    3.     GUI.skin=skin;
    after that you should be able to see the varaible skin in the inspector and assign your new skin
     
    Last edited: Sep 28, 2012
  4. Budgieboy

    Budgieboy

    Joined:
    Sep 6, 2012
    Posts:
    40
    Ahhh nice one.
     
  5. Budgieboy

    Budgieboy

    Joined:
    Sep 6, 2012
    Posts:
    40
    Oh my god, My game looks so much nicer now thank you so much!
     
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    you are welcome. :)
     
  7. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    How can i access the total number of seconds of all waves in continuos mode. i would like to create a slider similar to beware planet earth.
    also wanted to ask if modes can be switched mid game. meaning all waves but the one before last are continous and the one before last is wavecleared type so only after the last enemy dies i can spawn a boss.
    thanks in advance
     
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    you can calculate the total number for seconds of all waves in continous mode by using following function:

    Code (csharp):
    1.  
    2.     //pass the wave list variable of the SpawnManager
    3.     float GetAllWaveDuration(Wave[] waves){
    4.         float duration=0;
    5.        
    6.         //all the wave before the last one
    7.         for(int i=0; i<waves.Length-1; i++){
    8.             duration+=waves[i].waveInterval;
    9.         }
    10.        
    11.         //the last wave
    12.         float durationForLastWave=0;
    13.         foreach(SubWave subWave in waves[waves.Length-1].subWaves){
    14.             float tempDuration=subWave.count*subWave.interval+subWave.delay;
    15.             if(tempDuration>duration){
    16.                 durationForLastWave=tempDuration;
    17.             }
    18.         }
    19.        
    20.         duration+=durationForLastWave;
    21.        
    22.         Debug.Log("all wave will be spawned in "+duration+"s");
    23.         return duration;
    24.     }
    25.  

    Unfortunately the spawn mode cant be switched mid game as of now. I'll try to see if I can do anything about it. The only way that I can think of for now is use a Continous spawn mode but make the boss wave duration very very long, say 1000 minutes. So this way the next wave will never be spawned. But then you add a custom button which will pop up upon the boss wave is cleared. The button when pressed will start the next wave after the boss wave.

    You will have to track the boss wave by listening to the SpawnManager onWaveClearedE event and call SpawnManger.Spawn() function when the button is pressed. I'm afraid this is the easiet way I can think of for now.
     
  9. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    I've pasted your code in the SpawnManager, but where do I go from there? :|
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Call that function then. If you are calling it within SpawnManager, just something like

    Code (csharp):
    1. float totalSpawnDuration=GetAllWaveDuration(waves);
    and viola, totalSpawnDuration be the number you are looking for. :)

    If you are calling from other script, (you will need to make the the function public by adding public in front of the function. Like so:

    Code (csharp):
    1. public float GetAllWaveDuration(Wave[] wave)
    Then you will need a reference to the function, as such,

    Code (csharp):
    1. public SpawnManager spawnManager;
    2.  
    3. void YourFunction(){
    4.     float totalSpawnDuration=spawnManager.GetAllWaveDuration(spawnManager.waves);
    5. }
     
  11. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    thanks for the answers... you've been great... thanks a lot...

    another question...

    how can I offset the particle path indicator on the Y axis?

    thanks
     
  12. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the delay. I've been away for most of the weekend.

    There's not readily available ways to offset the particle path indicator on the Y axis? Without modifying the code anyway. However it's quite simple. You need to change following line73 in PathIndicator to:

    Code (csharp):
    1. Vector3 pos=new Vector3(subPath[subWPCounter].x, indicatorT.position.y+offsetY, subPath[subWPCounter].z);
    and of course, add a public variable offsetY by adding

    Code (csharp):
    1. public float offsetY;
    somewhere outside a function in the script. That will be the offset value.
     
  13. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    How to add a rail gun type tower that goes through the enemies, not the beam gun type, into the tdtk....
    plz help.....
     
  14. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    thanks so much for the help...

    is there a way to get the cost of the tower on the button and if no sufficient funds are available to tint the button icon?

    thanks
     
  15. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    never mind.. :) managed to do it on my own... sorry for the trouble...
     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Tsurugi, Just use DirectionalAOE tower type. You can set the angle (projecting arc) to very small so only creeps in the direct straight line of sight is damaged.
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick notice. TDTK v2.1.3 is now live on AssetStore. For information about the update, please check out the development blog.
     
  18. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    thanks songtan...
    but how do u make the enemies go in a straight line.. they seem to scatter around the path...
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The is actually a feature to dynamically place enemies all around the path so that the placement and formation look more organic. You can adjust scatter factor of the enemies on individual path. The parameter is "Dynamic WP". Just set that to zero and the enemies will line up perfectly.
     
  20. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    change the attribute on the path called dynamicWP to 0...
    hope this helps...
     
  21. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    @songtan @morobuse
    thank you so much...
     
  22. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    um... i used the DirectionalAOE tower type and it didnt went the way i wanted to.... i only does damage to the creep in front on it... i want it to go through it so creeps behind it will also get hurt....
     
  23. QI

    QI

    Joined:
    Oct 27, 2012
    Posts:
    229
    I think I found a bug .. when I restart game,I don't see the second wave !!!
     
  24. QI

    QI

    Joined:
    Oct 27, 2012
    Posts:
    229
    I think I found a bug .. when I restart game,I don't see the second wave !!!
     
  25. morobuse

    morobuse

    Joined:
    Sep 4, 2012
    Posts:
    11
    Hello again...

    was wondering how can I get the total number of units in a wave?
    the idea is that I am counting the kills and compare them to see if it was a perfect round, so I can give a points bonus in the end of the level.
    Similar to fieldrunners...

    thanks
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm very sorry about the slow respond. The mailing system has once again failed to notice me about new post.

    @Tsurugi, what are the setting you are using for the towers? Specifically the value for AOEConeAngle and Range?

    @QI, Thanks for letting me know. But unfortunately I'll need more information to fix that. Which scene are you restarting, your own custom scene or those examples? And by restart do you mean using the restart button of the default UI? Can you replicate the bug consistently everytime?

    @morobuse, I just send you a pm with the code extension required. Please let me know if you have any problem with it.
     
  27. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    how to make the pie chart more organize because i want it to go around the icon in the middle, not make an arc on top of the icon.......

    how do you make the tower respond to the enemies quicker because when they kill one creep they tend to stop and look for the next even when the creeps are in range.... and when i put the cool down time to 0.1 you still can see a slight lag when it looks for the next creep.... plz help....

    where can i specify when when i kill a creep i got resources because by default i get 1 but i want to change it....

    i making the game for android and i am have a problem with the camera.... what should be the resolution for the game..... how do you set up the camera....

    still try to figure out the rail gun tower thing......

    i know this is a lot of question but plz help.....

    thank you so much and i really like the tdtk....
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid you will have to dig into the code, specifically UI.cs. For a start you need to change line 309 from "float angle=200/(Mathf.Max(1, num-1));" to "float angle=360/(Mathf.Max(1, num-1));". That should give you a full circular pie. Then can adjust the offset of the position by changing the highlighted value in line313 and 314 as shown bellow. Change it to 180 to get the button dead centre.

    float x = pos.x+radius*Mathf.Sin((80)*Mathf.Deg2Rad+i*angle*Mathf.PI/180);
    float y = pos.y+radius*-Mathf.Cos((80)*Mathf.Deg2Rad+i*angle*Mathf.PI/180);

    Finally you can adjust the radius of the pie by adjusting the final parameter on line635, as highlited below. Just trail and error using any value until you get it right.

    Vector2[] piePos=GetPieMenuPos(currentBuildList.Length, screenPos, (int)1.414f*(width+height)/2);


    I just tried it and I dont really see any noticeable lag. Do they have problem when the creep are well within range? Or the lag only occur when the creep are entering the range of the tower? Are your platforms placed on equal height to the path.


    change the variable "value" on creep


    What problem precisely? Care to elaborate? The resolution is depend entirely on the device you are using in case for iOS and Android.


    I asked about some specific value about the setup in previous pos... value for AOEConeAngle and Range? How about this. send me a prefab of the tower in question and I'll try to configure it for you.
     
  29. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    OMG it helped me so much..... thx....

    for the rail gun i used the DirectionalAOE tower type andv alue for AOEConeAngle i tried 0-100 and value for the range i tried 0-50 the problem is the the tower is not shoot through the enemies..... for example if all the creeps are in a straight line (regardless to how many are there) and the rail gun tower is at the end all the enemies will get hit (all creeps that are in a straight line)

    the cancel button to the pie chart still not dead center when i change the highlight numbers to 180...

    is there a possible way to have a even number of towers to spread around evenly around because sometimes it will over lap one and another

    if i set the res to 480x320 what will happen if i put the game on a lower res phone?

    how to build resource tower when the creeps have not spawn yet..... i look at the code couldnt find the part where it defy it.....

    how do i specify the range for the support tower?

    thank you so much for answering my question......
     
  30. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You are confusing me, you say it's not shooting through enemies but then all the enemies in a straight line will get hit? I take it that shooting through enemies mean every enemies in the line of fire will get hit. So if all enemies in the line of fire is hit, that means it's working. How you want it to "shoot through" enemies?

    change line 649 to scatteredRectList[currentBuildList.Length]=new Rect(screenPos.x-width/2, Screen.height-screenPos.y-height, width, height);

    What exactly are you referring to?

    it depends on the device. if the device has a higher res than your build, you will get black border around the screen. if the device has a lower res than your build, partial of the gameview you see in editor is going to get cropped off.

    You cant. It's done that way because if allowed, it would be game-breaking. What stop the players from build a bunch of them to accumulate loads of resource before actually starting the game?

    It's termed "Effective Range".
     
  31. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    yea all the enemies in a straight line will get hit but i tried to configure it that way and it didnt work.....

    the maximum tower i can put in the pie chart is 7... when i try to put more (for example 8 towers or 9) the top icon will get overlap by another icon.....
    i just want to know if you can put more then 7 without the icons running into each other......

    than what should i specify my res because i want most android phones to work.....

    i want the players to build the resource towers before the game starts but the resource does not work unless the spawns start......
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Please send me a the current prefab you are using, I'll have a look, set it up and send it back to you.


    Insert this line if(num%2==0) num+=1; between line303 and 305 in UI.cs. That should do the trick.


    The first thing to do is to figure out what are the target resolution you are aiming for. The problem with android is that not all devices share a common resolution. You just have to pick one and go with it. Then you can set your editor resolution to that particular resolution you chose. From there you can adjust various camera, UI element on screen so that they fit withthe resolution. Normally the problem would be the UI cause the UI element are normally coded to occupy certain amount of pixel on the screen or appear at certain screen position. If any of those position specified exceed your screen resolution, they get cropped off. If you are using NGUI, what you see on the screen is what you get on the device. However it's a bit tricky if you use OnGUI(). you will need to dig into the code. The UI.cs are written for screen resolution of 1024x768 fyi.


    If you so wish, delete this section in BuildManager.cs, in line357,
    Code (csharp):
    1.  
    2.         if(tower.type==_TowerType.ResourceTower  GameControl.gameState==_GameState.Idle){
    3.             //GameMessage.DisplayMessage("Cant Build Tower before spawn start");
    4.             return "Cant Build Tower before spawn start";
    5.         }
     
  33. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    i attach a pic of the prefab......
     

    Attached Files:

  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    hm... everything seems right.

    The only thing I notice is that the tower seems to be targeting air unit only. So are you sure you have been testing with the right unit type? Try change it to hybrid just to be sure.
     
  35. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    Insert this line if(num%2==0) num+=1; between line303 and 305 in UI.cs. That should do the trick....um... i cant find the area to insert... please tell me what is the code before line 303......

    i want the railgun the damage every single creep in a straight line......which mean all the creep the on a straight path gets hit...... not one by one but all at once.....
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    it should look like this with the code added

    Code (csharp):
    1.     //calculate the position occupied by each individual button based on number of button, position on screen and button size
    2.     public Vector2[] GetPieMenuPos(int num, Vector3 pos, int size){
    3.         if(num%2==0) num+=1;
    4.         //first off calculate the radius require to accomodate all buttons
    5.         float radius=(num*size*1.8f)/(2*Mathf.PI);

    I understand. Given the setting you have shown me, it should do just that. I've tested it and it seems to be working. There's only reason that I can think of is that you have a very significant height difference between the creep and the tower's turret. So if the turret targeted and aim at particular creep, the line of fire wouldnt hit other creep along the path. Please see the image below. Can you just check. if possible, make sure the turret firing position is of the same height at which the creep is travelling.
     
  37. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    when u say adjust the height of the tower and path.. do u mean change the y-axis to zero?
    i want the tower to do this...... here is the pic...
     

    Attached Files:

  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately I cant see your image. Can you send them directly to my email? You can find it in the documentation.

    Yes, I do meant adjust the y-axis value. However it need not be zero, just make sure the height position of the tower's turretObject and path is same. say if path is positioned at y=10, make sure the tower's turret is positioned at y=10 too.
     
  39. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    songtan i sent the pic to your email but i didnt get your reply so can u post the email here just in case i didnt get the email wrong.....
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes, indeed I have. I've sent you an email in respond. Please check.
     
  41. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    $rail.jpg
    i have adjusted the y-axis to zero on the path, creeps, and towers..... didn't go as i wanted....
    the pic explains all... i want the tower to have a circular range indicator not a cone shape....
    well the pic say it all....

    another thing.... i realize the cancel button the to pie chart doesn't work and i dont really want it either because when i click on other area the pie chart will cancel itself... so i wonder which lines of code do i need to delete.....
     
  42. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    oh yea everything that gets touched by the blue line gets hard simultaneously...
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Now I can see what's the problem. Unfortunately the tower cannot damage creep beyond it's effective range. In other words, only creep withtin the attack range (green circle) will be damaged. You will have to modify the scripts to do so, by extending the range of the directional-aoe beyond the tower targeting range. You can do that by changing "range" in line743 in UnitTower.cs to whatever value you need. The easieat way would be add a modifier like such:

    if(built target!=null Vector3.Distance(thisT.position, target.thisT.position)<range*3f targetInLOS !stunned currentClip!=0){

    To have a circular range indicator, you will want to set your tower's "TargetingArea" to AllAround, not DirectionalCone. The range indicator indicate the target area where the tower will look for a potential target not the area which it will cause damage.


    Delete this section in function BuildMenuPie(). I cant really tell you which line since your script has been modified and would have different from mine.

    Code (csharp):
    1.         if(GUI.Button(scatteredRectList[currentBuildList.Length], "X")){
    2.             buildMenu=false;
    3.             BuildManager.ClearBuildPoint();
    4.             ClearBuildListRect();
    5.         }
     
  44. Dr_GeoFry

    Dr_GeoFry

    Joined:
    Nov 1, 2012
    Posts:
    5
    does anybody know how to use their own artwork for towers? I want to replace the generic towers with the ones that I have developed.
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for using the framework. :)

    Drag the tower prefab into the hierarchy tab. Expand it and you will see two child objects named base and turret. These are indeed the two default mesh used. You can simple replaced those two objects with your custom object. Then apply the changes for the prefab. Finally you will need to assigned the new objects as the turret and base object of the tower in TowerEditor (you will find this two slots in the bottom of column which is level1). Make sure you drag the object in the prefab in Project Tab (the one in hierarchy wont do).

    Feel free to contact me directly if you have any issue. I'll guide you through in more details.
     
  46. Tsurugi

    Tsurugi

    Joined:
    Sep 21, 2012
    Posts:
    97
    about the railgun tower thing i will find a better picture for it....

    this is going to be some work for you but hope u can solve my problem....

    the beam tower does damage over time=(DOT) and the DOT can be changed easily by going to the tower editor and changing some values
    but my question is can u change the damage DOT to have a formula (base attack+time^2) and code it so i can change the values in the tower editor.....
    hope u understand me question......
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I can do the modification for you but I'll need more detail about it. Like for how long the DOT run? Is it customizable? Does the tick interval customizable? Does various DOT effect from different tower stacks?

    Also please note that I will need time to do this but I'll get to it as soon as I have time.
     
  48. John-Sandrey

    John-Sandrey

    Joined:
    Jul 2, 2012
    Posts:
    119
    I was just wondering with the latest NGui update, the main NGui menu in the NGui examples gets a camera error and can not target the menu buttons. The free one still works when I install the TDTK, and NGui use to work before the latest update, not sure what was changed. If you can can you check up on this.
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'll look into it and sort it out asap. Are you using the latest NGUI or the lastest Unity (4.0)? or Both?

    Fyi, I havent update any of those two since the last time I added NGUI examples to TDTK. So it should help if you let me know the specifics. Thanks
     
  50. John-Sandrey

    John-Sandrey

    Joined:
    Jul 2, 2012
    Posts:
    119
    Latest NGui and Unity 3.5. The regular Unity GUI buttons work in the pause menu if that helps. But the NGui buttons in the NGui examples are there but not responding.
     
    Last edited: Nov 19, 2012