Button So Player Can't Click when Bool is True;

Hi. So I’m working on a little maze creator, and I have it set up so when you click one of the walls, it fills in and objects cant pass through it anymore. That’s working fine, but then I have a bool called isStarted to determine when the player hits the start button. I want it so when the player hits the start button, they can no longer click on the walls. I tried implementing the button and bool but for some reason its either always false or always true. I can’t figure it out. Thanks for any help you can offer.

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

public class WallTrigger : MonoBehaviour {

    public bool isStarted;
    SpriteRenderer sprite;
    Collider2D wallCollider;

    void Start () {
        sprite = GetComponent<SpriteRenderer> ();
        sprite.color = Color.white;
        wallCollider = GetComponent<Collider2D> ();
        wallCollider.isTrigger = true;

        isStarted = false;


    }
       

    void OnMouseDown() {
        if (isStarted != false) {
            if (sprite.color == Color.white) {
                sprite.color = Color.black;
                wallCollider.isTrigger = false;
            } else {
                sprite.color = Color.white;
                wallCollider.isTrigger = true;
            }
        }

    }

    public void StartFunction() {
        Debug.Log (isStarted);
        isStarted = true;
        Debug.Log (isStarted);
        Debug.Log("Pushed");
    }
       
}

Would I be correct at guessing that the “Wall” object exists many times in your scene (one for each wall)? If so, then you’re only modifying one of the many copies.

if you make isStarted static, it would be shared by all your walls, and that would probably solve the issue.

public static bool isStarted;

That worked! Thank you so much!