/// <summary> /// This method allows to apply the physics on this part. /// </summary> public void ApplyPhysics() { if (!BuildManager.Instance.UsePhysics) { return; } if (!AdvancedFeatures) { return; } if (!UseConditionalPhysics) { return; } if (AffectedByPhysics) { return; } if (CurrentState == StateType.Queue) { return; } for (int i = 0; i < PhysicsIgnoreTags.Length; i++) { GameObject[] IgnoreCollider = GameObject.FindGameObjectsWithTag(PhysicsIgnoreTags[i]); for (int x = 0; x < IgnoreCollider.Length; x++) { if (IgnoreCollider[x].GetComponent <Collider>() != null) { for (int y = 0; y < Colliders.Count; y++) { Physics.IgnoreCollision(Colliders[y], IgnoreCollider[x].GetComponent <Collider>()); } } } } if (GetComponent <Rigidbody>() != null) { if (PhysicsConvexOnAffected) { for (int i = 0; i < Colliders.Count; i++) { if (Colliders[i].GetComponent <MeshCollider>() != null) { Colliders[i].GetComponent <MeshCollider>().convex = true; } } } GetComponent <Rigidbody>().isKinematic = false; GetComponent <Rigidbody>().AddForce(UnityEngine.Random.insideUnitSphere, ForceMode.Impulse); } ChangeAreaState(OccupancyType.Free); AffectedByPhysics = true; DisableAllSockets(); PhysicExtension.SetLayerRecursively(gameObject, LayerMask.NameToLayer(Constants.LAYER_IGNORE)); Destroy(this); Destroy(gameObject, PhysicsLifeTime); EventHandlers.AffectedPart(this); }