I’m making a puzzle for my sport, the place it’s a must to manage pipes to transmit {an electrical} circulate from one level to a different. Every pipe middle accommodates a connector bucket and every finish accommodates the connector. After they contact one other, they kind a connection. The issue is that I can not set up connections reliably.
I wish to create a department algorithm for every middle, within the Discover Supply methodology, which collects every middle that’s linked to it by means of different related facilities, to search out that the one with a beginning worth is true (which is the unique energy supply). I’ve tried loops, however they should search every department.
With pipes regularly in movement, connections have to be made and disconnected in actual time.
Hub script to date:
public class ConnectorHub : MonoBehaviour
{
public Connector() connectors;
public Listing<ConnectorHub> connectedHubs = new Listing<ConnectorHub>();
public bool reside;
public bool begin;
public ConnectorHub src; //The orignal reside feed.
public UnityEvent OnLiveActice = new UnityEvent();
public UnityEvent OnLiveDeactice = new UnityEvent();
// Begin is known as earlier than the primary body replace
void Begin()
{
if (begin) src = this;
connectors= GetComponentsInChildren<Connector>();
}
personal void Replace()
{
FindSource();
}
void FindSource()
{
}
public void SetLive(bool worth)
{
//forestall repetition
if(reside == worth) return;
reside = worth;
if (reside)
OnLiveActice.Invoke();
else
OnLiveDeactice.Invoke();
}
}
Connector script:
(RequireComponent(typeof(Rigidbody)))
public class Connector : MonoBehaviour
{
public ConnectorHub hub;
public ConnectorHub related;
personal void Begin()
{
GetComponent<Rigidbody>().isKinematic = true;
GetComponent<Rigidbody>().useGravity = false;
hub = GetComponentInParent<ConnectorHub>();
}
personal void OnTriggerEnter(Collider different)
{
if (hub.begin) return;
if (different.GetComponent<Connector>())
{
related = different.GetComponent<Connector>().hub;
}
}
personal void OnTriggerExit(Collider different)
{
if (hub.begin) return;
if (different.GetComponent<Connector>())
{
related = null;
}
}
}