- Home /
Help me with the script on doing combo atk
hi everyone, its my first time to ask question here and im pretty much new in unity 3d but i manage work well in my first game... ive already did many tutorials and read some questions and answer here in forum... there is 1 thing i havent found is that...
i dont know the script or i dont have any idea how do i apply in my game, when doing some attacks but with different atk moves but not randomly doing atks instead a combo atk like in SPIDERMAN3, DEVILMAYCRY or ANY kind of action game... hope u get i mean here (cuz im bad in english and im not english guy hehe)... could anyone help me pls?
ive tried asking some ppl and even my professor in my school but it seems they dont know either... but in my mind it tells me i should use an array to call each atk constantly... am i right? pls help! very many thanks! more power UNITY USER!! =D
It's not very clear what you are asking..! Do you want somehow to catch for example if a player pressed a specific sequence of buttons? (Up > Down > Up > Left for example)
Answer by Lipis · Mar 13, 2010 at 01:16 AM
Here is a simple example on how can you do it.
- Create new
Javascript
and rename it toPlayerAttack
- Copy/paste the below code into it
- Drag the
PlayerAttack
script to yourFirst Person Controller
- Press the
Play
button to see it action
var fireRate: float = 2; var comboNum: float = 3; private var fired: boolean = false; private var timer: float = 0.0; private var comboCount: float = 0.0;
function Update () {
if (Input.GetButtonDown("Fire1")) { if (!fired) { fired = true; timer = 0.0; comboCount = 0.0; Debug.Log("I served a punch!"); //Do something awesome to deliver a punch! } else { comboCount++; if (comboCount == comboNum) { Debug.Log("I did a combo!");
//Do something awesome for the combo! } } }
if (fired) {
timer += Time.deltaTime;
if (timer > fireRate) {
fired = false;
}
}
}
The basic concept of this approach is that if you pressed Fire1
you are starting a timer
, and as long as the timer
is less than fireRate
(2 seconds in this example) you can't deliver more punches. Now during this time whenever the Player is pressing the Fire1
button you are increasing the comboCount
variable. If it's exactly comboNum
(3 in this example), you are ready to execute your combo function
.
hey how would I make it so that it animates an attack for each combocount?
Answer by stepcross36 · Mar 11, 2010 at 07:14 AM
what i mean is... when u press mouse1 button then it punch and if u continue or repeat press the mouse1 button it will make a combo atk instead a single punch
example... in devil may cry, when u press the atk button 3x, its doing a combo with 3 slash
please don't not post these kind of questions as answers.. use comments ins$$anonymous$$d or edit your question for giving a better description on your problem. Check the http://answers.unity3d.com/faq on how it works.. because it's not another forum.
Answer by stepcross36 · Mar 18, 2010 at 09:52 AM
tnx! this help me a lot! now i can apply this in my 3rd person controller! tnx!! great help!
@stepcross36 I updated the answer but don't post comments as answers.. Use the add comment
button for these kind of posts.. the post area is only for answers! good luck