Nevermind I just went and am rewriting the script.
Astrauk, try getting started with this… I’ve needed to do something like this for a while now, so I went and started it for you:
public var timeAllowedBetweenSwings : float = 0.5;
private var swingCounter : int = 0;
private var timeofLastSwing : float = 0;
function Start(){
Combo();
}
function Combo(){
while(true){
if(Input.GetButtonUp("Fire1")){
print(swingCounter);
swingCounter++;
timeofLastSwing = Time.time;
}
if(swingCounter == 3 || Time.time > (timeofLastSwing + timeAllowedBetweenSwings) ){
swingCounter = 0;
}
yield;
}
}
You could in theory do that in update, but I tend to do things with coroutines out of habit. That should work… it iterates swingCounter every time you hit Fire1, but if swingCounter ever reaches 3, or the user lets the time allowed between swings elapse, swingCounter will reset.
All you need to do is put your Switch(swingCounter) inside of the if(Input.GetButtonUp(“Fire1”)) and do your animations and whatnot.
I got this code almost working, I mean it works great except that after pressing “j” just once goes through all three if statements, and I’m having the worst time trying to figure out how to make it not do that.
var LastPress : float;
var timer : float;
var Ctime : float = 1;
var tap : int;
function Update () {
timer = Time.timeSinceLevelLoad;
//First Combo part
if(Input.GetKeyDown("j")){
tap = 1;
LastPress = Time.timeSinceLevelLoad;
Debug.Log("Combo Started: Attack One");
animation.PlayQueued("Attack1", QueueMode.PlayNow);
//Second Combo part
if(timer - LastPress < Ctime){
if(Input.GetKeyDown("j")){
if(tap == 1){
tap = 2;
LastPress = Time.timeSinceLevelLoad;
Debug.Log("Combo Prolonged: Attack Two");
animation.PlayQueued("Attack2", QueueMode.CompleteOthers);
}
}
//Third Combo part
if(timer - LastPress < Ctime){
if(Input.GetKeyDown("j")){
if(tap == 2){
tap = 3;
LastPress = Time.timeSinceLevelLoad;
Debug.Log("Combo Finished: Attack Three");
animation.PlayQueued("Attack3", QueueMode.CompleteOthers);
}}}
else{
Debug.Log("Combo Ended");
}}
else{
Debug.Log("Combo Ended");
}}}
Hmm, I really don’t feel like trying to fix that because its not formatted at all, but if you take my code I promise it works as advertised.