unit – How to watch a chain touching objects

I have a little logic problem. I have blocks that connect together to power it. So, when a block comes in contact with a powered block, it also becomes one. It also keeps a list of connected blocks and verifies that it is powered by at least one block.

There are also "source" blocks in the scene that are always fed and serve as a starting point.

All of this works well unless we get a break in the middle. In this case, even if they are no longer connected to a source block, the two blocks are connected to each other and remain in the "connected" state.

My question is similar to this question, but different in that my objects can be attached in any orientation and have any number of connections. In this case, some sort of routing would work because wire systems should not have more than 10 or 15 connections in total and only one active wire system at a time.

Here is the code if anyone is interested. Thank you in advance.

Classroom Conductor: MonoBehaviour
{

public bool isElectrified;
public bool isPowerSource;
public Material inactiveMaterial;
active material activeMaterial;

private list _conducteurs;
Private Renderer _renderer;


// ====
// Unity functions
// ====
empty Start ()
{
SetupPrivateVariables ();
CheckPowerSource ();
}

void Update ()
{
ProcessConductors ();
}

OnCollisionEnter (Collision Collision)
{
ProcessNewCollision (collision, true);
}

void OnCollisionExit (Collision Collision)
{
ProcessNewCollision (collision, false);
}


// ====
// Private functions
// ====
Private Vacuum ProcessConductors ()
{
if (isPowerSource)
{
return;
}

bool connectedConductorPower = false;

foreach (driver c in _conductors)
{
if (electrified)
{
connectedConductorPower = true;
}
}

if (connectedConductorPower)
{
_renderer.material = activeMaterial;
}
other
{
_renderer.material = inactiveMaterial;
}

isElectrified = connectedConductorPower;
}

CheckPowerSource () private empty
{
if (isPowerSource)
{
isElectrified = true;
_renderer.material = activeMaterial;
}
}

private void SetupPrivateVariables ()
{
_renderer = this.GetComponent();
}

ProcessNewCollision (Collision Collision, bool doAdd)
{
if (isPowerSource == false)
{
Orchestra head otherConductor = collision.collider.gameObject.GetComponent();

if (otherConductor! = null)
{
if (doAdd)
{
_conductors.Add (otherConductor);
}
other
{
_conductors.Remove (otherConductor);
}
}
}
}

}