UNITY3D 知识积累

//物体根据与相机距离可见

void CullDistance(int floor, float distance, Camera LookCamera)
    {
        float[] distances = new float[32];
        //设置某层可见性
        distances[floor] = distance;
        //将数组赋给摄像机的layerCullDistances
        LookCamera.layerCullDistances = distances;
    }

//相机渲染可见 基于mesh 可见

private void OnBecameVisible()
    {
        OnVisible(true);
    }

    private void OnBecameInvisible()
    {
        OnVisible(false);
    }

    // 相机层 控制

camera.cullingMask = ~(1 << x);  // 渲染除去层x的所有层
  
camera.cullingMask &= ~(1 << x); // 关闭层x
  
camera.cullingMask |= (1 << x);  // 打开层x

camera.cullingMask = 1 << x + 1 << y + 1 << z; // 摄像机只显示第x层,y层,z层

你可能感兴趣的:(Unity3D,知识积累,Unity3D)