private void AddGear(Vector3 pos) { GameObject gear = new GameObject(); gear.transform.position = pos; GearMesh gearMesh = gear.AddComponent <GearMesh>(); gearMesh.Build(1, 1.2f, 1.5f, 12); gearMesh.AddHingeJoint(); gearMesh.C_MR.material.color = Color.gray; }
private void AddFrontWheel(GameObject body, Vector3 position) { carElements[2] = new GameObject(); //build front wheel GearMesh frontWheelScript = carElements[2].AddComponent <GearMesh>(); float radius = Random.Range(0.4f, 0.6f); int sides = Random.Range(8, 12); frontWheelScript.Build(0.1f, radius, radius + 0.2f, sides, material); carElements[2].transform.position = position; //add motor frontWheelScript.AddHingeJoint(new JointMotor2D { motorSpeed = 300, maxMotorTorque = 1000 }, body.GetComponent <Rigidbody2D>()); frontWheelScript.C_MR.material.color = Color.black; frontWheelScript.SetPhysicsMaterialProperties(0, 10f); }
private void AddGearWithMotor(Vector3 pos, JointMotor2D C_JM2D) { //alternative way to add Mesh //add GameObject and move it to desired position GameObject gear = new GameObject(); gear.transform.position = pos; //add GearMesh component, build the Gear and add a motor GearMesh gearMesh = gear.AddComponent <GearMesh>(); gearMesh.Build(1, 1.2f, 1.5f, 12); gearMesh.AddHingeJoint(C_JM2D); //override default name gear.name = "Motor gear"; //set mesh's color gearMesh.C_MR.material.color = Color.gray; }