- Home /
how can make combat attack with different dmg?
hi i`m trying making a 2d game .i want make combat attack .attack after another attack after another attack.like a hack slash game ,like dmc. but my problem is when i click left click my first attack launch and after that when i try to click anotherone for next attack my anim will go to base anim and stop (my mean is unity will stop anim after launching first anim and next attack didnt launch) .i use this code for launching first attack and next attack and in animator i maked a transition from first attack to next attack .
if (anime.GetBool("attack_1"))
anime.SetBool("attack_1", false);
if (Input.GetKeyDown(KeyCode.Mouse0))
{
anime.SetBool("attack_1", true);
}
also i dont have any idea about how can manage dmg for every fram of anime. can anyone talk about that?
i search in google and forum but no usefull .so pls help !
Answer by CaffeineAndCoffee · Aug 13, 2018 at 10:31 AM
For having different animations played when attacking in a quick succession, you can have an int, called animToPlay. Also make a float, called timeSinceLastAttack. When you press the attack button, increment animToPlay by 1, and set timeSinceLastAttack to 0. Reset timeSinceLastAttack to 0. If you press the attack button quickly, you will run through all of the animations.
int animToPlay = 0;
float timeSinceLastAttack = 0;
float maxTimeBetweenAttacks = 1;
void Update () {
if (Input.GetMouseButtonDown(0)) {
if (timeSinceLastAttack > maxTimeBetweenAttacks) {
switch (animToPlay) {
case 0:
anim.Play("Attack 1");
case 1:
anim.Play("Attack");
}
timeSinceLastAttack = 0;
animToPlay++;
}
}
}
Can you go into further detail about damage?
@Smart_Guy12
i`m tried and maked it.
void Update()
{
//attack_1
if (anime.GetBool("attack_1"))
anime.SetBool("attack_1", false);
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0))
anime.SetBool("attack_1", true);
//attack_2
if (anime.GetBool("attack_2"))
anime.SetBool("attack_2", false);
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.$$anonymous$$ouse1) && attacking_1)
anime.SetBool("attack_2", true);
//attack_3
if (anime.GetBool("attack_3"))
anime.SetBool("attack_3", false);
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.$$anonymous$$ouse0) && attacking_2)
anime.SetBool("attack_3", true);
}
and maked transition from anystate to attack_1,attack_1 to(idle,attack_2),attack_2(attack_3,idle), attack_3 to idle.and i set 2 bool value attacking_1 attacking_2 .in recorder anime i change attacking_1 value to true in some frame i want .i did this for next attack . with those code every time is true and clicked will go for next attack. if have any question about this comment.
about dmg hmm.... my mean was dmg of sword change from every frame .example if sword of charachter is down no dmg if co$$anonymous$$g up get more dmg. first i didnt idea but after that plan for doing attack after attack , i think myb can set a float value and change it in frames .
but i have another problem now .when i click left click and after that right click for next attack i should get button down for 0.5 or it doesnt work .i change Get$$anonymous$$ey to Get$$anonymous$$eyDown but didnt solve. any idea????????
Your answer

Follow this Question
Related Questions
How to stop enemy from bumping into the player model but have it attack the player? 1 Answer
I need help with adding my character controller to a Character model 2 Answers
Merry Fragmas Character Controller for Unity 5 0 Answers
Does root transform (Y) work with Character Controller? 0 Answers
Localscale-flipped 2D character retains original rotation since 5.4 2 Answers