简体   繁体   English

如果在UNITY中没有附加渲染器,如何使我的3D Gameobject不可见?

[英]how to make my 3D Gameobject invisible if no renderer attached in UNITY?

I have 3D object and I want to make it invisible by turning off its rendering . 我有3D对象,我想通过关闭它的渲染使其不可见 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. " “回调中的异常:System.Reflection.TargetInvocationException:调用目标抛出了异常.---> UnityEngine.MissingComponentException: ”3dObject“游戏对象没有附加”渲染器“,但脚本正在尝试访问它。
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; 我正在使用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. 我正在使用vuforia,并希望在调用Tracking Lost函数后将最后跟踪的对象保留在屏幕上。
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.. 需要帮忙.. 在此输入图像描述

One approach could be: 一种方法可能是:

  1. Create a new layer called: InvisibleGO. 创建一个名为InvisibleGO的新图层。
  2. Set the layer of your GameObject to be InvisibleGO 将GameObject的图层设置为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 https://docs.unity3d.com/Manual/class-Camera.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM