public void loadPart(GameObject obj) { if (PartData.findChassis(obj.name) != null) { loadChassis(obj.name); } if (PartData.findWheel(obj.name) != null) { loadWheels(obj.name); } if (PartData.findArm(obj.name) != null) { loadArm(obj.name); } //sensors and arms }
public void loadArm(string partName) { if (!robot.transform.Find("Chassis")) { return; } while (removeAttached("Arm")) { ; } GameObject anchor = r.armAnchors [0]; GameObject w = Instantiate(PartData.findArm(partName)); w.transform.SetParent(robot.transform.Find("Chassis")); w.transform.position = anchor.transform.position; Vector3 rot = anchor.transform.rotation.eulerAngles; rot.z = 0; rot.y = 0; w.transform.localRotation = Quaternion.Euler(rot); w.transform.Rotate(new Vector3(0, 90, 90)); Claw c = w.GetComponent <Claw> (); HingeJoint[] hjs = w.GetComponentsInChildren <HingeJoint> (); foreach (HingeJoint hj in hjs) { hj.connectedBody = robot.transform.Find("Chassis").gameObject.GetComponent <Rigidbody>(); Vector3 pos = hj.gameObject.transform.position; hj.connectedAnchor = pos; hj.gameObject.transform.position = pos; } w.name = "Arm"; }