- I use script on prefab to instantiate many block to make rooms.
- I use a script to make bouds = of all instantiated children block of piece.
- My debug give good value ( i think ) in console.
- But is the white draw good value ? Why all go to 0 0 0 world ?
Script is here :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bound : MonoBehaviour {
void OnDrawGizmos()
{
Bounds bounds = GetChildRendererBounds(gameObject);
Gizmos.DrawWireCube(bounds.center, bounds.size);
Debug.Log(bounds +","+ gameObject);
}
Bounds GetChildRendererBounds(GameObject go)
{
Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
if (renderers.Length > 0)
{
Bounds bounds = renderers[0].bounds;
for (int i = 1, ni = renderers.Length; i < ni; i++)
{
bounds.Encapsulate(renderers*.bounds);*
}
return bounds;
}
else
{
return new Bounds();
}
}
}