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()
{
checkForLink();
}
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>*