привет помоги с рефакторингом public class CollisionError : MonoBehaviour {…
- User
привет помоги с рефакторингом public class CollisionError : MonoBehaviour { [SerializeField] private Collider objectCollider; [SerializeField] private float intersectionVolume; [SerializeField] private float wallVolume;
public bool exitTrigger { get; private set; } private void Start() { exitTrigger = true; } private void OnValidate() { objectCollider = GetComponent<Collider>(); } private void OnTriggerStay(Collider other) { if (other.CompareTag("Wall")) { if (!exitTrigger) return; Bounds wallBounds = objectCollider.bounds; Bounds otherBounds = other.bounds; Bounds intersection = GetIntersectionBounds(wallBounds, otherBounds); intersectionVolume = intersection.size.x * intersection.size.y * intersection.size.z; wallVolume = wallBounds.size.x * wallBounds.size.y * wallBounds.size.z; if (intersectionVolume > wallVolume / 4) { Debug.Log("стена пересекается более 25 % с другим объектом."); exitTrigger = false; } } } private void OnTriggerExit(Collider other) { if (other.CompareTag("Wall")) { exitTrigger = true; } } private Bounds GetIntersectionBounds(Bounds b1, Bounds b2) { Vector3 min = Vector3.Max(b1.min, b2.min); Vector3 max = Vector3.Min(b1.max, b2.max); if (min.x < max.x && min.y < max.y && min.z < max.z) { return new Bounds((min + max) / 2, max - min); } else { return new Bounds(Vector3.zero, Vector3.zero); } }}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.