Detect touches on ui element

I have a panel with the following script attached. All I want is to rotate the panel when moving my finger over it and open another menu when tapping it. The problem is that it works wherever I tap (blocking me from interacting with other buttons). So how could I detect touches on this specific object?

![public class RotateChY : MonoBehaviour {
    bool menuEnabled = true;
    bool moving = false;

    [SerializeField] float rotationSpeed = 1f;

    [SerializeField] GameObject chHolder;
    [SerializeField] GameObject chSelectionScreen;
    
    private void Start() {
        chHolder.SetActive(true);
        chSelectionScreen.SetActive(false);
    }

    private void Update() {
        if(Input.touchCount == 1){
            Touch screenTouch = Input.GetTouch(0);
            Debug.Log(EventSystem.current.currentSelectedGameObject + " is the current selected object");

            if(screenTouch.phase == TouchPhase.Moved) {
                menuEnabled = false;
                transform.Rotate(0, -screenTouch.deltaPosition.x * Time.deltaTime * rotationSpeed, 0);
                } 
                else if(screenTouch.phase == TouchPhase.Ended) {
                if(menuEnabled) {
                    openChSelectScreen(true);
                } else {
                    menuEnabled = true;
                }
            }
        }
    }

    public void openChSelectScreen(bool val) {
        chHolder.SetActive(!val);
        chSelectionScreen.SetActive(val);
        Debug.Log("called with " + val);
    }
}][1]

I have also tried with this statement, to check if the tapped object is my panel, but it didn't work at all. if(Input.touchCount == 1 && EventSystem.current.IsPointerOverGameObject(0) && EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.CompareTag("CharacterHolder"))

1 Answer

1

You could use an Event Trigger component and add an Event Like PointerEnter / Exit or Pointer Down / up

Apparently my taps are not detected on the built version...