如果未在UNITY中附加渲染器,如何使我的3D Gameobject不可见? [英] how to make my 3D Gameobject invisible if no renderer attached in UNITY?

查看:426
本文介绍了如果未在UNITY中附加渲染器,如何使我的3D Gameobject不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3D对象,我想通过关闭其渲染使其不可见.但是当我在运行时中运行代码时,它显示:: ::
回调中的异常:System.Reflection.TargetInvocationException:调用的目标抛出了异常.---> UnityEngine.MissingComponentException:"3dObject"游戏对象没有附加"Renderer" ,但是脚本正在尝试访问它. "
我想知道是否没有渲染器,然后我如何才能在场景/游戏视图中看到该对象.而且在检查器中什么也没有(网格渲染器/渲染器/网格过滤器).
我正在使用 c#:this.GetComponent<Renderer>().enabled=true;
我正在使用 vuforia ,并希望在调用跟踪丢失"功能后将最后跟踪的对象保留在屏幕上.
OR 还有其他方法可以做到这一点吗?
我是一个团结的新手,我知道这是一个非常基本的问题,但一无所获.需要帮忙..

I have 3D object and I want to make it invisible by turning off its rendering. But when I run the code in runtime it shows ::
" Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> UnityEngine.MissingComponentException: There is no 'Renderer' attached to the "3dObject" game object, but a script is trying to access it."
I want to know if There is no renderer then how I am able to see that object in scene/game view. and also in inspector nothing is there (mesh renderer / renderer / mesh filter).
I'm Using c# : this.GetComponent<Renderer>().enabled=true;
I'm using vuforia and want to keep last tracked object on screen after Tracking Lost function is called.
OR Is there any other way to do this...?
I'm new in unity and I know its a pretty basic question but not getting anything. Need Help..

推荐答案

一种方法可能是:

  1. 创建一个名为InvisibleGO的新层.
  2. 将GameObject的图层设置为InvisibleGO
  3. 然后您可以设置剔除蒙版 每个摄影机上的摄影机只显示您所要的图层 想要
  1. Create a new layer called: InvisibleGO.
  2. Set the layer of your GameObject to be InvisibleGO
  3. Then you can set the culling mask for the camera on each camera to only display the layers that you want:

https://docs.unity3d.com/Manual/class-Camera.html

这篇关于如果未在UNITY中附加渲染器,如何使我的3D Gameobject不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆