- Home /
Event Trigger Pointer Exit sometimes not recognized
Hi, I have some weird behaviours on my 2D unity project. I have touch controls left and right button. I'm using Event Triggers Pointer Exit and Pointer Enter because I want that the user can move the thumb without leaving the screen and the player change the direction. This works! My player controller has some knockback built in, if you get hit or collide with an enemy there is a knockback.
if (knockbackCount <= 0) {
player.velocity = new Vector2 (moveVelocity, player.velocity.y);
playerCollider.enabled = true;
playerRenderer.color = new Color(1f,1f,1f,1f);
} else {
Move (0);
if (knockFromRight) {
player.velocity = new Vector2 (-knockback, 0);
playerCollider.enabled = true;
playerRenderer.color = new Color (1f, 1f, 1f, .5f);
}
if (!knockFromRight) {
player.velocity = new Vector2 (knockback, 0);
playerCollider.enabled = true;
playerRenderer.color = new Color(1f,1f,1f,.5f);
}
playerRenderer.color = new Color (1f, 1f, 1f, 1f);
knockbackCount -= Time.deltaTime;
playerRenderer.color = new Color(1f,1f,1f,.5f);
}
Sometimes it happen, if you are on an left or right button and get hit, that the Trigger Pointer Exit is not recognize and the player is still moving without having the thumb on the button nor on the screen. I then need to press the button again. I also tried using the Pointer Up but it didn't helped and as you can see I stop the moving in the knockback part.
Any help suggestions?
Cheers, Armin