I am making a puzzle for my recreation, the place it’s important to organize pipes to transmit {an electrical} stream from one level to the opposite. Every pipe heart comprises a connector hub and every finish comprises the connector. Once they contact one other, they type a connection. The issue is that I can not reliably set connections.
I wish to create an branching algorithm for every hub, within the discover supply technique, that collects each single hub that is linked to it by means of different related hubs, to seek out the one with begin worth being true (which is the unique supply of energy). I’ve tried for loops, however they should search each single department.
With pipes regularly transferring, connections must be made and disconnected in actual time.
Hub Script thus far:
public class ConnectorHub : MonoBehaviour
{
public Connector[] connectors;
public Checklist<ConnectorHub> connectedHubs = new Checklist<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)
{
//stop 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;
}
}
}