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
Create new `Javascript` and rename it to `PlayerAttack`
Copy/paste the below code into it
Drag the `PlayerAttack` script to your `First 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`.
See also documentation for `Input` and `Time` classes.
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