Game Object Chains

Hi. Im trying to make gameobject-chain system.

Ill try to explain what i mean. For example i have power plant object. If other object is in power plant radius then it's active. If third object connected to second object that is connected to power plant - third object will be active. And so on.

I tried to do that with raycast hit, collisions but system doesnt work correctly.

   var linked = 0;
    var number = 100000;
    var pos = Vector3[];

    function Awake()
    pos = new Array(4); ( something like that ) 


    function Update()

    function checkForLink()
    pos[0] = Vector3.up
    pos[1] = -Vector3.up
    pos[2] = Vector3.right
    pos[3] = -Vector3.right

    var hit = Raycasthit (blablabbla)
    var hit_range = 32; // 

    for (var i=0; i<4; i++)
    if (phisics.raycast(transform.position,pos*,hit,hit_range)*
 *if (hit.collider.tag=="base"&&link==0)*
 *var ob: GameObject;*
 *ob = hit.collider.gameobject;*
 *if (ob.GetComponent(script).link==1&&ob.GetComponent(script).number<number)*
 *link = 1;*
 *number = ob.GetComponent(script).number + 1*
*<p>some pseudo code to understand what i did. I managed to make system that will check for object link to the power plant, but i dont know how to make check in situations when for example some objects are sticked together but are not linked to powerplant - so they must be inactive. Other situation is when i need to unlink object if there are no objects to link with in right left up down sides. Ofcource I made some scripts to handle that but they conflicted with first checklink script so sometimes an object that was linked "flipped" from linked status to unlinked when he shouldnt.</p>*
*<p>Can anyone please help with that kind of algorithm?* 
*I understand scheme but cant properly code it in unity.</p>*
*<p>PS ( its a pseudo2d game) There is a real example of what i need in flash "The Space Game" or in SimCity, where you must build pipes to connect pump-house with other houses.</p>*

For such a case i would recommend Physics.OverlapSphere. That way yon don't have gaps between your rays and the overall math for the physics system is a lot easier.

Well, the connection problem. You could setup the whole “net” and then doing some kind of A* algorithm but i think that’s too complicated for such a case.

It's better to have some kind of a "LinkedTo" variable that holds a reference to the node itself is connected to (assuming there's always just one source). Every node checks for neigbours and check their linkedto variable. If there's something referenced (not null) we set our LinkedTo variable to this node. A Special case would be the powerplant of course.

It sounds to me like the Onslaught gamemode in UT2004 or like in the game Perimeter, am i right?