Simple cell-based game goes bonkers when clicked on the edge of the cell
I'm creating a simple casual game in which you click on cells to change their colours according to some rules. I'm using tweening to make the tapping animations responsive and it's all cool but when you click right on the edge of the cell (have to do it on a phone, can't replicate it with a mouse), the cell gets weirdly "stuck" in this loop where it just goes smaller and larger repeatedly (ie. firing the onMouseEnter() and onMouseExit() tweens) for some time until it comes to a halt.
This is the code doing the tweening when you hover the cell or exit it:
void OnMouseEnter()
{
centerPivot.DOScale(.8f, .1f).SetId(555);
Debug.Log(this.name + " entered");
}
void OnMouseExit()
{
centerPivot.DOScale(1f, .3f);
Debug.Log(this.name + " exited");
}
Here's a vide of the problem in action (first the correct clicking is shown and then what happens when you click on the edge - and you can see in the console log that the logs for entering and quitting the cell are going on and on until you click outside of it): video link
Why is that so? I've tried tons of things, like giving the tweens IDs and killing them or introducing states to the code but it doesn't help a bit, it's as if the code catches the finger clicking the edge of the cell on multiple frames and then fires the respective onMouseEnter() and OnMouseExit()'s discarding that the enter and exit had already happened instead of just doing: a finger on the edge happened -> OnMouseEnter() -> the cell gets slighlty smaller due to the tween but the finger is already lifted off -> OnMouseExit().
Instead of this, it looks like it's going:caught the finger on the edge on 60 frames so let's do the OnMouseEnter() -> OnMouseExit() cycle for each of the qualifying frames where the finger stood on the screen even though it's been ages since it's off.
Any ideas?
Your answer
Follow this Question
Related Questions
Error CS1026: Unexpected symbol ;, expecting ) 0 Answers
Best way to detect touch on a GameObject 5 Answers
Touch does not work with the new Input System 5 Answers
Sprite/gameObject touch or click event 0 Answers