i want to detect if i touch on UI button then our gameobject is not move in the direction of the touch.
the problem is when in touch on button, gameobject also move is the direction of touch. look at the image when I touch on the LAUNCH button my pabble which carries ball also move in the direction of launch button on X-axis.
but i want it to not move when i touch on any button on screen.
here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class paddle : MonoBehaviour
{
//public float playerspeed = 1000;
public float directionalspeed = 50;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float movehorizontal = Input.GetAxis("Horizontal");
transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(Mathf.Clamp(gameObject.transform.position.x + movehorizontal, -1.7261f, 1.7261f), gameObject.transform.position.y, gameObject.transform.position.z), directionalspeed * Time.deltaTime);
//mobile controls
Vector2 touch = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 10f));
if (Input.touchCount > 0)
{
transform.position = new Vector3(touch.x, transform.position.y, transform.position.z);
}
}
}