public void RegisterConnection(ConnectionPoint connectionPoint) { bool isBadEndConnection() { return(connectionPoint.connectionType == ConnectionPoint.ConnectionType.OUTPUT || start == connectionPoint || connectionPoint.wire != null); } bool isBadStartConnection() { return(connectionPoint.connectionType == ConnectionPoint.ConnectionType.INPUT); } if (currentState == State.ZERO_CONNECTED) { // Can only start connection at Output and end at Input if (isBadStartConnection()) { backToZeroConnected(); } else { lineRenderer.enabled = true; start = connectionPoint; if (connectionPoint.wire != null) { currentState = State.ALREADY_CONNECTED; } else { currentState = State.ONE_CONNECTED; } UpdateLineRenderer(); } } else if (currentState == State.ONE_CONNECTED) { if (isBadEndConnection()) { backToZeroConnected(); } else { Wire wire = Instantiate(wirePrefab, new Vector3(0, 0, 0), Quaternion.identity); wire.AddStartConnection(start); wire.AddEndConnection(connectionPoint); wire.Register(); backToZeroConnected(); } } else if (currentState == State.ALREADY_CONNECTED) { if (isBadEndConnection()) { backToZeroConnected(); } else { lineRenderer.enabled = false; Wire wire = start.wire; if (connectionPoint.wire == null) { wire.AddEndConnection(connectionPoint); wire.Register(); } backToZeroConnected(); } } }