Hey, I have been trying to get touch screen controls working for awhile now. But I just can’t get it to work the way I want it to. I have one gui button at the moment to move to the right, but when I touch the button the cube only moves slightly and I have to keep pressing the button to move any further. Is there away to get this to move constantly when I touch down on the button and then stop when it’s not touched? the only way I got this working was by using the Input.touchCount >= 1
but that will only work for one direction can anyone help me? please.
here is my code after a few attempts
//Vectors for movement directions
private Vector3 left,right;
//Float for speed
private float speed;
//Boolean to check if button is touched
private bool touched;
//Setting variables initial values
void Start ()
{
touched = false;
speed = 2f;
//Values for movement along the X-axis
left = new Vector3(-speed,0,0);
right = new Vector3(speed,0,0);
}
void Update ()
{
//calling the movement method
applyMovement();
}
private void OnGUI()
{
//If the button and the screen is touched set the touched boolean to true
if(GUI.Button(new Rect(10,10,150,150),"RIGHT") && Input.touchCount >= 1)
{
touched = true;
}
else
{
touched = false;
}
}
private void applyMovement()
{
if(touched)
{
//apply positive movement along the x-axis when touched
transform.Translate(right);
}
}