void Add_DrivingComponents(GameObject gameObject, string direction) { // Rigidbody Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>(); rigidbody.mass = Wheel_MassProp.floatValue; // HingeJoint 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 Drive_Wheel_CS driveScript = gameObject.AddComponent <Drive_Wheel_CS>(); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); }
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 Set_Wheel(string direction, Vector3 position, int number, int parentNumber) { // Create RoadWheel GameObject GameObject wheelObject = new GameObject("RoadWheel_" + direction + "_" + number); wheelObject.transform.parent = thisTransform; wheelObject.transform.localPosition = position; if (direction == "L") { wheelObject.transform.localRotation = Quaternion.identity; } else { wheelObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180.0f); } // Mesh MeshFilter meshFilter = wheelObject.AddComponent <MeshFilter> (); meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh; MeshRenderer meshRenderer = wheelObject.AddComponent <MeshRenderer> (); meshRenderer.material = Wheel_MaterialProp.objectReferenceValue as Material; // Rigidbody Rigidbody rigidbody = wheelObject.AddComponent <Rigidbody> (); rigidbody.mass = Wheel_MassProp.floatValue; // SphereCollider SphereCollider sphereCollider = wheelObject.AddComponent <SphereCollider> (); sphereCollider.radius = Wheel_RadiusProp.floatValue; sphereCollider.center = Vector3.zero; sphereCollider.material = Wheel_Collider_MaterialProp.objectReferenceValue as PhysicMaterial; // HingeJoint HingeJoint hingeJoint; hingeJoint = wheelObject.AddComponent <HingeJoint> (); hingeJoint.anchor = Vector3.zero; hingeJoint.axis = new Vector3(0.0f, 1.0f, 0.0f); hingeJoint.connectedBody = thisTransform.Find("ChildArm_" + direction + "_" + parentNumber).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>(); // 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; 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; }
void Create_Wheel(string direction, Vector3 position) { // Create 'Parent_of_Wheel' GameObject parentObject = new GameObject("Parent_of_Wheel_" + direction); parentObject.transform.parent = thisTransform.Find("Hub_" + direction); parentObject.transform.localPosition = position; parentObject.transform.localRotation = Quaternion.Euler(0, 0, 90); // Create Wheel GameObject wheelObject = new GameObject("SteeredWheel_" + direction); wheelObject.transform.parent = parentObject.transform; if (direction == "L") { wheelObject.transform.localPosition = new Vector3(0.0f, Wheel_DistanceProp.floatValue / 2.0f, 0.0f); wheelObject.transform.localRotation = Quaternion.Euler(0, 0, 0); } else { wheelObject.transform.localPosition = new Vector3(0.0f, -Wheel_DistanceProp.floatValue / 2.0f, 0.0f); wheelObject.transform.localRotation = Quaternion.Euler(0, 0, 180); } // Mesh 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; // SphereCollider SphereCollider sphereCollider = wheelObject.AddComponent <SphereCollider> (); sphereCollider.radius = Wheel_RadiusProp.floatValue; sphereCollider.center = Vector3.zero; sphereCollider.material = Wheel_Collider_MaterialProp.objectReferenceValue as PhysicMaterial; // HingeJoint HingeJoint hingeJoint; hingeJoint = wheelObject.AddComponent <HingeJoint> (); hingeJoint.connectedBody = parentObject.transform.parent.GetComponent <Rigidbody> (); hingeJoint.anchor = Vector3.zero; hingeJoint.axis = new Vector3(0.0f, 1.0f, 0.0f); // 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>(); // 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; }
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; }