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 loadWheels(string partName) { if (!robot.transform.Find("Chassis")) { return; } for (int a = 0; a < 4; a++) { removeAttached("Wheel"); } int count = 0; foreach (GameObject anchor in r.wheelAnchors) { GameObject w = Instantiate(PartData.findWheel(partName)); w.transform.SetParent(robot.transform.Find("Chassis")); w.transform.position = anchor.transform.position; Vector3 rot = anchor.transform.rotation.eulerAngles; rot.x = 0; rot.y = 0; w.transform.localRotation = Quaternion.Euler(rot); Wheel wheel = w.GetComponent <Wheel> (); if (anchor.transform.localPosition.y > 0) { w.transform.Rotate(new Vector3(180, 0, 0)); wheel.backwards = true; } else { w.transform.Rotate(new Vector3(180, 0, 0)); wheel.backwards = false; } r.wheels [count] = wheel; count++; //w.transform.rotation = anchor.transform.rotation; HingeJoint hj = w.GetComponent <HingeJoint> (); hj.connectedBody = robot.transform.Find("Chassis").gameObject.GetComponent <Rigidbody>(); hj.axis = new Vector3(0, 1, 0); w.name = "Wheel"; } }