void Set_Physics_Wheel(GameObject wheelObject, string direction) { // Rigidbody Rigidbody rigidbody = wheelObject.AddComponent <Rigidbody>(); rigidbody.mass = Wheel_MassProp.floatValue; // HingeJoint HingeJoint hingeJoint = wheelObject.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 Drive_Wheel_CS driveScript = wheelObject.AddComponent <Drive_Wheel_CS>(); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); // Wheel_Resize_CS if (Wheel_ResizeProp.boolValue) { Wheel_Resize_CS resizeScript = wheelObject.AddComponent <Wheel_Resize_CS>(); resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue; resizeScript.Return_Speed = Return_SpeedProp.floatValue; } // Fix_Shaking_Rotation_CS Fix_Shaking_Rotation_CS fixScript = wheelObject.AddComponent <Fix_Shaking_Rotation_CS>(); fixScript.Is_Left = (direction == "L"); fixScript.This_Transform = wheelObject.transform; // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; }
void Create_Wheel(string direction, int number) { // Create gameobject & Set parent. GameObject wheelObject = new GameObject("RoadWheel_" + direction + "_" + number); wheelObject.transform.parent = thisTransform; // Set position. Vector3 pos; if (Set_IndividuallyProp.boolValue) { pos.x = Mathf.Sin(Mathf.Deg2Rad * (180.0f + Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue)) * Sus_LengthProp.floatValue; pos.z = Mathf.Cos(Mathf.Deg2Rad * (180.0f + Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue)) * Sus_LengthProp.floatValue; } else { pos.x = Mathf.Sin(Mathf.Deg2Rad * (180.0f + Sus_AngleProp.floatValue)) * Sus_LengthProp.floatValue; pos.z = Mathf.Cos(Mathf.Deg2Rad * (180.0f + Sus_AngleProp.floatValue)) * Sus_LengthProp.floatValue; } pos.z -= SpacingProp.floatValue * (number - 1); pos.y = Wheel_DistanceProp.floatValue / 2.0f; if (direction == "R") { pos.y *= -1.0f; } wheelObject.transform.localPosition = pos; // Set rotation. if (direction == "L") // Left { wheelObject.transform.localRotation = Quaternion.Euler(Vector3.zero); } else // Right { wheelObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180); } // Mesh if (Wheel_MeshProp.objectReferenceValue) { MeshFilter meshFilter = wheelObject.AddComponent <MeshFilter> (); meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh; MeshRenderer meshRenderer = wheelObject.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; } // Rigidbody Rigidbody rigidbody = wheelObject.AddComponent <Rigidbody> (); rigidbody.mass = Wheel_MassProp.floatValue; // HingeJoint HingeJoint hingeJoint = wheelObject.AddComponent <HingeJoint> (); hingeJoint.anchor = Vector3.zero; hingeJoint.axis = new Vector3(0.0f, 1.0f, 0.0f); hingeJoint.connectedBody = thisTransform.Find("Suspension_" + direction + "_" + number).gameObject.GetComponent <Rigidbody> (); // SphereCollider SphereCollider sphereCollider = wheelObject.AddComponent <SphereCollider> (); sphereCollider.radius = Wheel_RadiusProp.floatValue; sphereCollider.center = Vector3.zero; sphereCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial; // Drive_Wheel_CS Drive_Wheel_CS driveScript = wheelObject.AddComponent <Drive_Wheel_CS> (); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); // Fix_Shaking_Rotation_CS if (Fit_ST_FlagProp.boolValue == false) // for Physics Tracks { Fix_Shaking_Rotation_CS fixScript = wheelObject.AddComponent <Fix_Shaking_Rotation_CS>(); fixScript.Is_Left = (direction == "L"); fixScript.This_Transform = wheelObject.transform; } // Wheel_Resize_CS if (Fit_ST_FlagProp.boolValue == false) // for Physics Tracks { if (Wheel_ResizeProp.boolValue) { Wheel_Resize_CS resizeScript = wheelObject.AddComponent <Wheel_Resize_CS> (); resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue; resizeScript.Return_Speed = Return_SpeedProp.floatValue; } } // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; // Set Layer wheelObject.layer = Layer_Settings_CS.Wheels_Layer; }