accessing variables from nearby gameobjects (Prim's Algorithm)

Hey everyone. I’m trying to make a labyrinth with a randomly generated map

like this one: Random Maze-Generating with Prim's Algorithm (UNITY3D) - YouTube

I currently have given each point a randomly generated number, but how can I check to see if the number of adjacent points are larger or smaller?

This is what I currently have:

var number : float;


function Start() {
number = Random.Range(1,255);
}

Would I need to change var number to a static variable?

Are the blocks touching? If they are you can use the collision system. If they’re not touching just shoot rays out of all the sides. You can then access the objects off of the hit data. Setting it static would mean that it would be the same across all instances of the class. So if you changed it in one object it would change in all of them. I don’t feel like that’s what you’re after, hence my suggestion to use rays or collisions and then use GetComponent to access the remote var.

Tag all squares/cubes with a word like “square”, then do :

function findclosest(){
var allsquares = findallwithtag"square";
for (var square in allsquares){
if (distance (current square,square)<(diameter of squares*1.5))
}

(pseudocode)
then you have the closest, you can make an array of the gameobjects, then make a new loop that compares the value of centre to all neighbours.