public void TriggerPlug(GameObject plug) { // was GameObject instead of Plug if (plug == startPlug) { startPlug = null; ShouldShowPlug(plug, false); cord.RemoveStart(); } else if (plug == endPlug) { endPlug = null; ShouldShowPlug(plug, false); cord.RemoveEnd(); } else if (!(startPlug != null && endPlug != null)) // i.e. only one plug is null and we're about to finish a connection { if (startPlug == null) { startPlug = plug; ShouldShowPlug(plug, true); cord.SetStart(plug.transform); } else // endPlug == null; there's no other option { endPlug = plug; ShouldShowPlug(plug, true); cord.SetEnd(plug.transform); } // connection is completed, let's see if the player got it right... if (startPlug != null && endPlug != null) // !(plugs == null) will always return true { var plugs = ToPlugEnds(); tryTransmission(plugs); } } var _startPlug = (startPlug != null) ? startPlug.GetComponent <Plug>().ToString() : "null"; var _endPlug = (endPlug != null) ? endPlug.GetComponent <Plug>().ToString() : "null"; Debug.Log("startPlug: " + _startPlug + "| endPlug: " + _endPlug); }
public void triggerPlug(GameObject plug) { if (plug == startPlug) { startPlug = null; cord.RemoveStart(); } else if (plug == endPlug) { endPlug = null; cord.RemoveEnd(); } else if (startPlug == null) { startPlug = plug; cord.SetStart(plug.transform); } else if (endPlug == null) { endPlug = plug; cord.SetEnd(plug.transform); } else { // Do nothing because both plugs are assigned var plugs = toPlugEnds(); if (plugs != null) { isValidTransmission(plugs); } } var _startPlug = (startPlug != null) ? startPlug.GetComponent <Plug> ().ToString() : "null"; var _endPlug = (endPlug != null) ? endPlug.GetComponent <Plug> ().ToString() : "null"; Debug.Log("startPlug: " + _startPlug + "| endPlug: " + _endPlug); }