- Home /
How to control touch commands.
Hello everyone,
I have been working on a project for quite some time now and I can not find out how to solve the issue that I'm having with touchscreen commands. I currently have a touch script that tells the tap value to increment everytime the player touches the kick button and the other conditions are met.
//Check to see if the player is attacking and if the timer is less than equal than 0
if (playerScript.IsComboAnimationPlaying == false && touchKick == true && timer <= 0)
{
//If conditions are met, increment the tap value per key press
tap++;
//Keep record of the last time the attack button was pressed
LastPress = Time.timeSinceLevelLoad;
}
//Check to see if the player is attacking
if (playerScript.IsComboAnimationPlaying == false)
{
//If conditions are met, start the timer
timer -= Time.deltaTime;
//Check to see if the timer value is less than equal to 0
if (timer <= 0)
{
//If conditions are met, set timer to the resetTimer value, which is 0
timer = restTime;
}
}
The problem I have is conditioning the tap value to only change once the attack animation is completed. I have this ---> playerScript.IsComboAnimationPlaying used as an animation event to control the animation flow. Works fine. As of now, I can touch my kick guitexture and the tap value will increment every time I touch that texture despite my player attack is condition to work one at a time. Can anyone give me any advice to control a user's touch to only be detected once the player's animation has completed. Thanks for you time.
Note: The timer is an alternative that I do not like using because each animation has a different animation length and using timer is currently causing delays in the animation flow. It is inaccurate and do not work will with the animations I have but it does force the tap value to only change when the timer is 0.
I cannot see any major flaw in this script, can you provide a sample from the playerScript. Also if you log the isComboAnimationPlaying variable in update, is it working as expected?
Thanks for your response zeppike. The isComboAniamtionPlaying variable is working perfect in the update script. Here is a snippet of the combo script that controls the animation flow:
void Combo ()
{
if(attack)
{
switch (tap)
{
case 0:
//Reset to Idle
anim.Play("kyo_idle");
break;
case 1:
//Combo Start
anim.SetBool("kickAttack1", true);
IsComboAnimationPlaying = true;
comboTimer = 0.5333334f;
StartCoroutine(ShowCurrentClipLength());
//Cause tap to increment after this animation. $$anonymous$$ay need to use AnimationEvent
//Debug.Log ("Tap: " + tap);
break;
case 2:
//Combo Prolonge
//Debug.Log ("Now on the second kick!");
anim.SetBool("kickAttack2", true);
IsComboAnimationPlaying = true;
comboTimer = 0.3291925f;
StartCoroutine(ShowCurrentClipLength());
break;
case 3:
//Combo Finished
anim.SetBool("kickAttack3", true);
IsComboAnimationPlaying = true;
comboTimer = 0.3409091f;
StartCoroutine(ShowCurrentClipLength());
//Debug.Log ("tap: " + tap);
break;
}
//Every attack command, allow comboTimer to start
//comboTimer = comboResetTimer;
}
}
Here is where I have the isComboAnimationPlaying function that turns the value to false once the animation is over:
void AnimationIsOver()
{
IsComboAnimationPlaying = false;
anim.SetBool("kickAttack1", false);
anim.SetBool("kickAttack2", false);
anim.SetBool("kickAttack3", false);
anim.SetBool("punchAttack1", false);
anim.SetBool("punchAttack2", false);
//Debug.Log ("isComboAnimationPlaying: " + IsComboAnimationPlaying);
//Debug.Log ("Animation has finished");
}
All this works fine, I just would like to set my tap value, so that it works in the same way.