首页 > 解决方案 > Unity 中关于实例化对象的 AABB 错误的原因是什么?

问题描述

已编辑: 显示错误日志的图像。所以我有一个脚本来识别项目列表,删除当前项目,然后重新生成原始对象。这在 80% 的情况下有效,但在其他 20 次出现 AABB 错误,我不知道原因是什么。有任何想法吗?

标签: c#unity3d

解决方案


AABB 与表示轴对齐边界框的边界框有关。您的 AABB 可能没有正确对齐,这就是您收到错误的原因。有一个脚本显示您的对象如何绘制它们的边界框,以便您可以轻松设置它们。

using UnityEngine;
using System.Collections;

public class BoundingBox: MonoBehaviour
{
    void OnDrawGizmos()
    {
        Renderer rend = GetComponent<Renderer>();
        if (rend)
        {
            Gizmos.color = Color.yellow;
            Gizmos.DrawWireCube(rend.bounds.center, rend.bounds.size);
        }
    }

//If your object is not within the bounding boundaries, then you can set your mesh up manually like this;

     void Start()
     {
       var meshFilter = GetComponent<MeshFilter>();
       meshFilter.mesh.bounds = new Bounds(transform.position, new Vector3(10, 5, 1));
     } 
}


推荐阅读