コード例 #1
0
    private void AddGear(Vector3 pos)
    {
        float innerRadius = Random.Range(0.3f, 0.5f);
        float rootRadius  = innerRadius + Random.Range(0.1f, 0.5f);
        float outerRadius = rootRadius + Random.Range(0.3f, 0.5f);
        int   sides       = Random.Range(3, 17);

        GearMesh gear = GearMesh.AddGear(pos, innerRadius, rootRadius, outerRadius, sides, material);

        gear.AddHingeJoint();

        gear.GetComponent <MeshRenderer>().material.color = Color.gray;
    }
コード例 #2
0
    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;
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    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;
    }