Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Attack Combo Script [Finished]

Discussion in 'Scripting' started by TheChronicPhenix, Dec 31, 2010.

  1. TheChronicPhenix

    TheChronicPhenix

    Joined:
    Jan 14, 2010
    Posts:
    874
    For anyone that's interested I finally got my attack combo script finished, here it is.

    Code (csharp):
    1. var LastPress : float;
    2. var timer : float;
    3. var Ctime : float = 1;
    4. var tap : int;
    5. var attack : boolean = true;
    6. var Atime : float = 2;
    7. var Aspeed : float = 2;
    8.  
    9. function Update(){
    10.  
    11. timer = Time.timeSinceLevelLoad;
    12. if(Input.GetKeyDown("j")){
    13. LastPress = Time.timeSinceLevelLoad;
    14. if(tap > 2){
    15. tap = 1;
    16. }
    17. else{
    18. tap++;
    19. }
    20. Combo();
    21. }
    22. if(timer - LastPress > 1){
    23. tap = 0;
    24. if(timer - LastPress < Atime){
    25. attack = false;
    26. }
    27. else{
    28. attack = true;
    29. }
    30. }
    31. }
    32.  
    33. function Combo () {
    34. //WaitForSeconds(2);
    35. if(attack){
    36. switch (tap){
    37.  
    38. case 0:
    39. //Reset to Idle
    40. break;
    41.  
    42. case 1:
    43. //Combo Start
    44. Atime = animation["Attack1"].length;
    45. animation.PlayQueued("Attack1", QueueMode.PlayNow);
    46. break;
    47.  
    48. case 2:
    49. //Combo Prolonged
    50. Atime += animation["Attack2"].length;
    51. animation.PlayQueued("Attack2", QueueMode.CompleteOthers);
    52. break;
    53.  
    54. case 3:
    55. //Combo Finished
    56. Atime += animation["Attack3"].length;
    57. animation.PlayQueued("Attack3", QueueMode.CompleteOthers);
    58. break;
    59. }
    60. }
    61. }
     
  2. Kotzu

    Kotzu

    Joined:
    Dec 26, 2010
    Posts:
    41
    what do you mean combo attack? like make the mob/npc/player for example "target + use hook + bring target + cast spell/attack" ?
     
  3. TheChronicPhenix

    TheChronicPhenix

    Joined:
    Jan 14, 2010
    Posts:
    874
    No not like that, it's just a simple press "attack" multiple times to play attack animations in order, and if you don't then it resets to the first animation.
     
  4. Anton1274

    Anton1274

    Joined:
    Dec 7, 2013
    Posts:
    10
    If can be helpfull i used this statment to make play an animation after a key was pressed once, to play all the animation without interruptions:-
    if( Input.GetButton("Fire3") || (animation.IsPlaying("animation_name") && animation["animation_name"].time < animation["animation_name"].length ){
    animation.CrossFade("animation_name");
    }
     
  5. MIAmelia3477

    MIAmelia3477

    Joined:
    Jul 10, 2015
    Posts:
    1
    What happens when a player isn't constantly attacking? Won't the timer and LastPressed eventually become larger than Atime and make attack false?
     
  6. Nirav-Madhani

    Nirav-Madhani

    Joined:
    Jan 8, 2014
    Posts:
    27
    Please Check
    http://u3d.as/t6n
    Basically it is cheat code system but supports attack combo system