Starting script after tap/click

I’ve got an EnemySpawner object with a script attached. The script simply spawns the enemies in my scene. As of right now (before trying to implement the tap to start) the script runs and the enemies spawn immediately after clicking the play button. What I want to do is implement a ‘Tap to start’ in my scene where the enemies start spawning only after the player taps the screen. I figured I must somehow use the Start function but I’m not entirely sure.

My EnemySpawner script:

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

public class EnemySpawnerScriptt : MonoBehaviour

    public GameObject enemy;
    public GameObject enemy2;
    public GameObject enemy3;
    float randX;
    Vector2 whereToSpawn;
    public float spawnRate = 2f;
    float nextSpawn = 0.0f;

    // Start is called before the first frame update
    void Start()

    // Update is called once per frame
    void Update()
        if (Input.GetMouseButtonDown(0) == true)
            bool started = true;
            while (started == true)
                if (Time.time > nextSpawn)
                    nextSpawn = Time.time + spawnRate;
                    randX = Random.Range(-2.4f, 2.4f);
                    GameObject[] enemyArray = { enemy, enemy2, enemy3 };
                    int randEnemy = UnityEngine.Random.Range(0, enemyArray.Length);
                    whereToSpawn = new Vector2(randX, transform.position.y);
                    Instantiate(enemyArray[randEnemy], whereToSpawn, Quaternion.identity);

This doesn’t work. I need just one initial click to start the script and if this matters I want to be able to implement a replay button later on which starts the game again from an initial click to start.

Hey @bobmcdonal, try moving the while loop to be outside the input if statement. Or just delete the while loop (not the stuff inside) and put this line of code above the left over stuff inside the while loop:

if (started != true) return;