Help with boolean updating on all instances of script

I am trying to create a hex grid map where the player can hit x to explore the current hex and the boolean for that hex changes to true. I have had no luck referencing individual instances from the character controller script, so now and trying my luck at the explore function of the hex script on my instanced prefab on the hex grid.

However, when I press x at runtime, all the hexes with the script update, rather than the one that the character controller is currently colliding with.

I have a feeling I am doing something stupid here and would appreciate some direction.

Code:
void Update ()
{
if (Input.GetButtonDown (“Explore”))
{
ExploreHex ();

		}
	}

	private void ExploreHex()
	{
		//Determine time passed from exploring
		
		if (Explored ==false)
		{
			
			//timePassed = timePassed + 24;
			
			//Calculate time passed and period of day	
			//daysPassed = (timePassed / 24);
			//hoursPassed = timePassed - (daysPassed * 24);
			//whatPeriodofDay ();
			
			//Set hex to Explored
			Explored = true;
			Debug.Log ("You explore the Hex");
		}
		else 
		{
			Debug.Log ("The Hex has already been Explored");
		}
	}

Also, Explored is initialized here:

public bool Explored;

Update is called on all game objects in the game, not just the one the game object is controlling…

You may want to wrap you code in something like this…

If (being_controlled) { … }

and set a bool value for that object while you are controlling it to true.

Try something like this:

  • Remove the check from your HexDetail
  • make the ExploreHex method public
  • Make sure every hex has a collider, not your hexgrid a single one!
  • create a new script to attach to the player

public class HexExplorer : MonoBehaviour {
  void Update() {
    if (Input.GetButtonDown ("Explore"))
    {
      RaycastHit hit;
      if (Physics.Raycast(transform.position+Vector3.up, -Vector3.up, out hit, 100f))
      {
        HexDetail theHex = hit.collider.gameObject.getComponent<HexDetail>();
        if (theHex != null) theHex.ExploreHex();
      }
    }
  }
}