Hey guys im trying to make a td platformer for Android phone. I have a few touch buttons that the player will press on their screen to make the character move. Im going to focus on the right arrow. When the right arrow is pressed and held, the player walks right. When the player releases the right arrow, the character stops moving right. All is good except that when the right arrow is held down, if the player slides their finger off of the arrow button (while never letting go of the screen), the character still keeps walking right. Basically what i want is for the bottom to stop functioning if the player moves slides their finger off of the button. I was told to use OnPointerExit but im not sure how to incorporate it into my script.
This is what I have in my “Touch Script” for the Right Arrow:
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Touch : MonoBehaviour
{
private Player player;
public bool IsPointerOverGameObject();
void Start()
{
player = FindObjectOfType<Player>();
}
public void RightArrow()
{
player.moveright = true;
player.moveleft = false;
}
public void ReleaseRightArrow()
{
player.moveright = false;
}
public void OnPointerExit(EventSystems.PointerEventData eventData);
}
It just gives me an error saying that the namespace for EvenSystems isnt recognizable. Here is the code attached to the “Player” (character) that pertains to the Right Arrow:
if (Input.GetKey(KeyCode.RightArrow))
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
transform.localScale = new Vector3(1, 1, 1);
}
if (moveright)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
transform.localScale = new Vector3(1, 1, 1);
}
I really want to get this going but unfortunately im a little lost. Any help on how to modify my code would be great! Thanks Guys! ![]()