- Home /
Touchscreen Combo System Issue
Hey Everyone, I have been working with a combo script that I've found online some time ago and I wanted to make modifications to it. I've had success with the script and using Input.GetButton commands for a game controller but now I'm having issues with the script in regards to using the touchscreen and guiTextures. I will break my problem down by presenting the issue and stating the goal of what I'm trying to accomplish. Thanks in advance to anyone who has the bandwidth to assist.
Problem: Game is detecting a touch on the screen before and during the animation of an attack. Goal: I'm trying to have the game detect a touch on the screen (kick button, punch button, etc.) only before and after an animation is performed. The catch to this is the fact that I need each tap to represent an animation, i.e. tap 1 should perform "kickAttack1", etc.
Unfortunately the following snippet does two things: the integer tap is incremented and a switch statement is executed.
void Combo () { if(attack && IsComboAnimationPlaying == false) { //Make record of the time from which the player has last pressed the attack button
LastPress = Time.timeSinceLevelLoad;
//If tap value is greater than 2 set the tap value equal to 1
if (tap > 2 && IsComboAnimationPlaying == false)
{
tap = 1;
}
else
{
tap++;
}
//Check to see if the last time the attack button is pressed, is greater than 1 second. If so, reset tap value to zero.
if (timer - LastPress > 1)
{
tap = 0;
if (timer - LastPress < Atime)
{
attack = false;
}
else
{
attack = true;
}
}
switch (tap)
{
case 0:
//Reset to Idle
anim.Play("kyo_idle");
break;
case 1:
//Combo Start
//anim.Play("kyo_lk1");
anim.SetBool("kickAttack1", true);
IsComboAnimationPlaying = true;
Debug.Log ("tap: " + tap);
break;
case 2:
//Combo Prolonge
anim.SetBool("kickAttack2", true);
IsComboAnimationPlaying = true;
Debug.Log ("tap: " + tap);
break;
case 3:
//Combo Finished
anim.SetBool("kickAttack3", true);
IsComboAnimationPlaying = true;
Debug.Log ("tap: " + tap);
break;
}
}
}
The code works fine but not in the way I would like for it to work. This next line of code, is a snippet of the condition that I use to start the entire code that you see above.
if (IsComboAnimationPlaying == false)
{
if (touchKick == true && grounded == true && crouch == false)
{
Combo ();
}
}
The touchKick boolean is associated with the following:
if (guiKick.HitTest (myTouch.position, Camera.main) && IsComboAnimationPlaying == false)
{
touchKick = true;
guiKick.color = Color.white;
}
Again the code works like a charm but it does two things that I HATE: 1) constantly increments tap as many times as you touch the kick button, 2) the code cycles through the switch statement and cause a random animation system to occur, i.e. if I was to tap three times, I would like for the code to execute each case in a chronological order but it just does a random cycle like "kickAttack1", "kickAttack2", and "kickAttack2" or sometimes "kickAttack1", "kickAttack1", and "kickAttack2". I know this is a ton of verbiage and explaination but I'm sure it is a logical fix to this. If anyone has the time and want a unique puzzle to solve, by all means take a look at my dilemna. Any advance, any tips, and suggestions are all welcome here. Thanks for your time.
NOTE: If anyone is wondering what IsComboAnimationPlaying is, it is a boolean used as an Animation Event for each of my animations. When I perform an attack, IsComboAnimationPlaying = true. Once the animation is complete, IsComboAnimationPlaying = false, which is the function I've created to turn IsComboAnimationPlaying off.
Your answer
Follow this Question
Related Questions
Problem with Android Keyboard/TextField 1 Answer
Resetting Combos 1 Answer
How to do this GUI 2 Answers
Guitexture script to do something a normal key does. 0 Answers
Combo Attack/Animator issue 0 Answers