void Create_Static_Wheel(string direction, Vector3 position)
        {
            GameObject gameObject = Create_GameObject("SprocketWheel", direction, position);

            Add_Mesh(gameObject);
            // Static_Wheel_CS script
            PTS_Static_Wheel_CS staticScript = gameObject.AddComponent <PTS_Static_Wheel_CS> ();

            staticScript.Radius_Offset = Radius_OffsetProp.floatValue;
        }
Beispiel #2
0
        void Create_Wheel(string direction, Vector3 position, int number)
        {
            // Create a new gameobject.
            GameObject gameObject = new GameObject("SupportWheel_" + direction + "_" + number);

            gameObject.transform.parent        = thisTransform;
            gameObject.transform.localPosition = position;
            if (direction == "L")
            {
                gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero);
            }
            else
            {
                gameObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180.0f);
            }
            gameObject.layer = PTS_Layer_Settings_CS.Wheels_Layer;             // Wheel
            // Mesh
            MeshFilter meshFilter = gameObject.AddComponent <MeshFilter> ();

            meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh;
            MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer> ();

            Material[] materials = new Material [Wheel_Materials_NumProp.intValue];
            for (int i = 0; i < materials.Length; i++)
            {
                materials [i] = Wheel_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material;
            }
            meshRenderer.materials = materials;
            // SphereCollider
            SphereCollider sphereCollider = gameObject.AddComponent <SphereCollider> ();

            sphereCollider.radius   = Wheel_RadiusProp.floatValue;
            sphereCollider.center   = Vector3.zero;
            sphereCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial;
            // for Physics Wheel.
            if (Static_FlagProp.boolValue == false)
            {
                // Rigidbody
                Rigidbody rigidbody = gameObject.AddComponent <Rigidbody> ();
                rigidbody.mass = Wheel_MassProp.floatValue;
                // HingeJoint
                HingeJoint hingeJoint = gameObject.AddComponent <HingeJoint> ();
                hingeJoint.anchor        = Vector3.zero;
                hingeJoint.axis          = new Vector3(0.0f, 1.0f, 0.0f);
                hingeJoint.connectedBody = thisTransform.parent.gameObject.GetComponent <Rigidbody> ();
                // Drive_Wheel_CS
                PTS_Drive_Wheel_CS driveScript = gameObject.AddComponent <PTS_Drive_Wheel_CS> ();
                driveScript.Radius     = Wheel_RadiusProp.floatValue;
                driveScript.Drive_Flag = Drive_WheelProp.boolValue;
                // Wheel_Resize_CS
                if (Wheel_ResizeProp.boolValue)
                {
                    PTS_Wheel_Resize_CS resizeScript = gameObject.AddComponent <PTS_Wheel_Resize_CS> ();
                    resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue;
                    resizeScript.Return_Speed   = Return_SpeedProp.floatValue;
                }
                // Stabilizer_CS
                gameObject.AddComponent <PTS_Stabilizer_CS> ();
            }
            else                 // for Static Wheel
            {
                PTS_Static_Wheel_CS staticScript = gameObject.AddComponent <PTS_Static_Wheel_CS> ();
                staticScript.Radius_Offset = Radius_OffsetProp.floatValue;
            }
        }