public IEnumerator Loader() { if (savedSpaceShip.shipName != "") { savedSpaceShip.partIndex = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".savedSpaceShip.partIndex"); myAPoints = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".myAPoints"); targetAPoints = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".targetAPoints"); int[] serialID = new int[savedSpaceShip.partIndex.Length]; thisPartAttachPoint = null; otherPartAttachPoint = null; thisParts = new ShipPart[savedSpaceShip.partIndex.Length]; otherParts = new ShipPart[savedSpaceShip.partIndex.Length]; ShipPart thisPart = null; ShipPart otherPart = null; int value; for (int i = 0; i < savedSpaceShip.partIndex.Length; i++) { thisPart = (ShipPart)Instantiate(partInstantiator.GetComponent <PartInstantiator>().partList[savedSpaceShip.partIndex[i]], (Vector2)(Camera.main.transform.position), Quaternion.Euler(-90, 180, 0)); int.TryParse(thisPart.name, out value); thisPart.name = (i + 100 + value).ToString(); int.TryParse(thisPart.name, out value); serialID [i] = value; otherPart = GameObject.Find(serialID[thisPart.attachedToIndex].ToString()).GetComponent <ShipPart>(); thisParts[i] = thisPart; otherParts[i] = otherPart; if (i == 0) { loadedShip = thisPart.gameObject; } shipScaleVertical += thisPart.GetComponent <BoxCollider>().size.y; } yield return(new WaitForEndOfFrame()); for (int i = 0; i < myAPoints.Length; i++) { Transform[] children = thisParts[i + 1].GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if ((child.name == "attachPoint(up)" && myAPoints[i] == 1) || (child.name == "attachPoint(down)" && myAPoints[i] == 2)) { thisPartAttachPoint = child.GetComponent <AttachPoint>(); } } children = otherParts[i + 1].GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if ((child.name == "attachPoint(up)" && targetAPoints[i] == 1) || (child.name == "attachPoint(down)" && targetAPoints[i] == 2)) { otherPartAttachPoint = child.GetComponent <AttachPoint>(); } } thisPartAttachPoint.otherAttachPoint = otherPartAttachPoint; thisPartAttachPoint.Attach(); } } else { Debug.Log("Load failed."); } }