- Home /
Touches too frequent and animations
Hi, I have a problem with animations and touches or pressed keys. Here's my code:
if (Input.touchCount > 0){
foreach (Touch touch in Input.touches){
switch (touch.phase){
case TouchPhase.Began :
landerAnimator.SetTrigger("BoostInit");
break;
case TouchPhase.Ended :
landerAnimator.SetTrigger("BoostEnd");
break;
}
}
}
if(Input.GetButtonDown("Jump")){
landerAnimator.SetTrigger("BoostInit");
}
if(Input.GetButtonUp("Jump")){
landerAnimator.SetTrigger("BoostEnd");
}
if (Input.GetButton("Jump") || Input.GetMouseButton(0)) {
landerAnimator.SetTrigger("Boost");
}
In my game I have a rocket that turns on the engine (boost) every time the user press the space bar or touches the screen. In addition I have three animations: one triggered when the user press the space bar or touching the screen, one when the user keeps pressing or touching and another one when the user releases the key or stops touching.
This code works fine when the game is played "normally" so that touches occurs with some delay one from the other. If the user spams the spacebar or the touches, the animations start overlapping and not working in the correct order or remaining in the wrong state (i.e. the rocket keeps the boosting animation even when nothing is pressed/touched).
Is there a way to ignore touches or button pressed too quickly or is there a problem with my code? Could it be the animations states?
Thanks in advance.
Use an exit time in your animator. $$anonymous$$ake the transitions atomic.
or ins$$anonymous$$d or Trigger, you can use Bool as pareters in the animator, just show boost animation when bool is true.
Unfortunately exit times are already set and transitions are atomic too. There seems to be a problem expecially with double or multi clicks. The animations remains in the init or boost animation even after the button/touch release.
Your answer
Follow this Question
Related Questions
how to solve MissingComponentException: There is no 'Animator' attached to the "Ethan 1" game object 1 Answer
Animator in assetbundle from iphone app not play 1 Answer
How do I code legacy animations in wrap mode Unity C# 0 Answers
Animator: Adjust speed of Animations at every keyframe? 0 Answers
Load recorded animation from TXT file 0 Answers