using System.Collections; using System.Collections.Generic; using UnityEngine; public class Furniture : MonoBehaviour { protected Bounds combinedBounds; protected Vector3 centerOffset; protected void Start() { CalculateBounds(); } // Update is called once per frame void Update() { } private void CalculateBounds() { if (GetComponent() != null) { combinedBounds = GetComponent().bounds; } else { combinedBounds = new Bounds(transform.position, Vector3.zero); } var renderers = GetComponentsInChildren(); foreach (Collider child in renderers) { if (child != GetComponent()) { if (combinedBounds == null) { combinedBounds = child.bounds; } else { combinedBounds.Encapsulate(child.bounds); } } } //combinedBounds = renderers[0].bounds; centerOffset = transform.position - combinedBounds.center; } }