using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Furniture : MonoBehaviour
{
    public Bounds combinedBounds;
    protected Vector3 centerOffset;
    protected void Start()
    {
        CalculateBounds();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void CalculateBounds()
    {
        if (GetComponent<Renderer>() != null)
        {
            combinedBounds = GetComponent<Renderer>().bounds;
        }
        else
        {
            combinedBounds = new Bounds(transform.position, Vector3.zero);
        }
        var renderers = GetComponentsInChildren<Collider>();
        foreach (Collider child in renderers)
        {
            if (child != GetComponent<Renderer>())
            {
                if (combinedBounds == null)
                {
                    combinedBounds = child.bounds;
                }
                else
                {
                    combinedBounds.Encapsulate(child.bounds);
                }
            }
        }
        //combinedBounds = renderers[0].bounds;
        centerOffset = transform.position - combinedBounds.center;
    }
}
