void Finishing(string Direction)
 {
     // Add RigidBody and BoxCollider.
     for (int i = 1; i <= transform.childCount; i++)
     {
         Transform Temp_Transform = transform.Find("TrackBelt_" + Direction + "_" + i);
         if (Temp_Transform)
         {
             GameObject Temp_Object = Temp_Transform.gameObject;
             // Add RigidBody.
             if (Temp_Object.GetComponent <Rigidbody>() == null)
             {
                 Rigidbody Temp_RigidBody = Temp_Object.AddComponent <Rigidbody> ();
                 Temp_RigidBody.mass = Track_Mass;
             }
             // Special Offset for Unity5.
             if (i % 2 == 0)
             {
                 Temp_Transform.position += Temp_Transform.forward * Special_Offset;
             }
         }
     }
     // Add HingeJoint.
     for (int i = 1; i <= transform.childCount; i++)
     {
         Transform Temp_Transform = transform.Find("TrackBelt_" + Direction + "_" + i);
         if (Temp_Transform)
         {
             GameObject Temp_Object = Temp_Transform.gameObject;
             if (Temp_Object.GetComponent <HingeJoint>() == null)
             {
                 HingeJoint Temp_HingeJoint;
                 Temp_HingeJoint            = Temp_Object.AddComponent <HingeJoint> ();
                 Temp_HingeJoint.anchor     = new Vector3(0.0f, 0.0f, Spacing / 2.0f);
                 Temp_HingeJoint.axis       = new Vector3(1.0f, 0.0f, 0.0f);
                 Temp_HingeJoint.breakForce = BreakForce;
                 Transform Temp_Connected_Transform;
                 Temp_Connected_Transform = transform.Find("TrackBelt_" + Direction + "_" + (i + 1));
                 if (Temp_Connected_Transform)
                 {
                     if (Temp_Connected_Transform.GetComponent <Rigidbody>())
                     {
                         Temp_HingeJoint.connectedBody = Temp_Connected_Transform.GetComponent <Rigidbody>();
                     }
                 }
                 else
                 {
                     Temp_Connected_Transform = transform.Find("TrackBelt_" + Direction + "_1");
                     if (Temp_Connected_Transform)
                     {
                         if (Temp_Connected_Transform.GetComponent <Rigidbody>())
                         {
                             Temp_HingeJoint.connectedBody = Temp_Connected_Transform.GetComponent <Rigidbody>();
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 void Finishing(string Direction)
 {
     // Add RigidBody.
     for (int i = 1; i <= Parent_Transform.childCount; i++)
     {
         Transform Temp_Transform = Parent_Transform.Find("TrackBelt_" + Direction + "_" + i);
         if (Temp_Transform)
         {
             GameObject Temp_Object = Temp_Transform.gameObject;
             // Add RigidBody.
             Rigidbody Temp_RigidBody = Temp_Object.AddComponent <Rigidbody> ();
             Temp_RigidBody.mass = Track_MassProp.floatValue;
             // for Static_Track
             if (Static_FlagProp.boolValue)
             {
                 Temp_RigidBody.drag = 10.0f;
             }
             // Special Offset for Unity5.
             if (i % 2 == 0)
             {
                 Temp_Transform.position += Temp_Transform.forward * Special_OffsetProp.floatValue;
             }
         }
     }
     // Add HingeJoint.
     for (int i = 1; i <= Parent_Transform.childCount; i++)
     {
         Transform Temp_Transform = Parent_Transform.Find("TrackBelt_" + Direction + "_" + i);
         if (Temp_Transform)
         {
             GameObject Temp_Object = Temp_Transform.gameObject;
             HingeJoint Temp_HingeJoint;
             Temp_HingeJoint            = Temp_Object.AddComponent <HingeJoint> ();
             Temp_HingeJoint.anchor     = new Vector3(0.0f, 0.0f, SpacingProp.floatValue / 2.0f);
             Temp_HingeJoint.axis       = new Vector3(1.0f, 0.0f, 0.0f);
             Temp_HingeJoint.breakForce = BreakForceProp.floatValue;
             Transform Temp_Connected_Transform;
             Temp_Connected_Transform = Parent_Transform.Find("TrackBelt_" + Direction + "_" + (i + 1));
             if (Temp_Connected_Transform)
             {
                 Temp_HingeJoint.connectedBody = Temp_Connected_Transform.GetComponent <Rigidbody> ();
             }
             else
             {
                 Temp_Connected_Transform = Parent_Transform.Find("TrackBelt_" + Direction + "_1");
                 if (Temp_Connected_Transform)
                 {
                     Temp_HingeJoint.connectedBody = Temp_Connected_Transform.GetComponent <Rigidbody> ();
                 }
             }
         }
     }
 }