OnTouch screen works but UI Button doesnt

hello,

I have a scene in my gave where a player can just create aloud of fireworks (mini game) but I want to have a button to exit this. I have set up the UI and canvas correctly but it still doesn’t work and I think the firework script is overwriting the Button click and is just setting off a firework.

my Script for fireworks is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fireworks : MonoBehaviour
{

    List<GameObject> prefabList = new List<GameObject>();
    public GameObject Prefab1;
    public GameObject Prefab2;
    public GameObject Prefab3;
    public GameObject Prefab4;
    public GameObject Prefab5;
    public GameObject Prefab6;
    public GameObject Prefab7;
    public GameObject Prefab8;

    // Start is called before the first frame update
    void Start()
    {
        prefabList.Add(Prefab1);
        prefabList.Add(Prefab2);
        prefabList.Add(Prefab3);
        prefabList.Add(Prefab4);
        prefabList.Add(Prefab5);
        prefabList.Add(Prefab6);
        prefabList.Add(Prefab7);
        prefabList.Add(Prefab8);

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position);

            if (touch.phase == TouchPhase.Began)
          
            {
            int prefabIndex = UnityEngine.Random.Range(0, 8);
            Instantiate(prefabList[prefabIndex], touchPos, Quaternion.identity);

            }

        }
    }
}

it there something I need to do to make a button work?

thanks,

Why not just make your list public and add the stuff to it in the inspector?

I believe you can use this to check if over a button Redirecting to latest version of com.unity.ugui

Ooo I did look at this but I thought it was only for mouse click and not finger touch but I’ve noticed the section at the bottom.

Will try this tonight. Thanks!