generated from VR-Sexe/Unity3DTemplate
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
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<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;
|
|
}
|
|
}
|