Hi guys, I’ve written a code that moves the player left or right if you touch the left or right side of the screen but I have a small problem.
When I hold down the left side of the screen and move my finger to the right side and release it, moveLeft remains true and the player keeps moving left. I know it’s a condition problem but I can’t find it, I feel so stupid because it seems so easy.
Touch touch = Input.GetTouch(i);
if(touch.position.x < Screen.width/2)
{
if(touch.phase == TouchPhase.Began)
moveLeft = true;
if(touch.phase == TouchPhase.Ended)
moveLeft = false;
}
if(touch.position.x > Screen.width/2)
{
if(touch.phase == TouchPhase.Began)
moveRight = true;
if(touch.phase == TouchPhase.Ended)
moveRight = false;
}
What can I do to prevent that effect ? Thanks for reading.