断言在表达式 go isactive () && 上失败go gettag() != 0 unity [英] assertion failed on expression go isactive () && go gettag () != 0 unity
问题描述
此错误对我的游戏开发无害,但时不时看到它会伤害我的眼睛.我怎样才能在 unity 上摆脱这个错误.
This error is harmless to my game development but it hurts my eye by seeing it from time to time . How can i get rid of this error on unity .
断言失败:断言在表达式上失败:'go.IsActive() &&go.GetTag() != 0'UnityEngine.Camera:get_main()
Assertion failed: Assertion failed on expression: 'go.IsActive() && go.GetTag() != 0'UnityEngine.Camera:get_main()
当我使用标签找到一个对象时它就出来了
It came out when i find an object using tag
public GameObject shadowUnderWater;
void OnEnable(){
//uSkyManager Instantiates
if(shadowUnderWater == null){
shadowUnderWater = GameObject.FindGameObjectWithTag("SkyManager");
}
}
到目前为止我所做的是:
What i did so far is this :
void Awake(){
Camera.main.GetComponent<Camera> ();
}
我将相机设置为 Awake
功能,因为我在某些论坛上看到您只需要实例化相机.
I set the camera on the Awake
function because i saw in some forum the you just need to instantiate the camera.
推荐答案
- 无需获取相机组件
- 如果相机为空,那么显然从中获取组件将失败
- 你在 Awake 中所做的一切毫无意义,没有准备/获取相机的概念
请参阅有关如何使用此成员的文档:https://docs.unity3d.com/ScriptReference/Camera-main.html
See the documentation on how to use this member: https://docs.unity3d.com/ScriptReference/Camera-main.html
这是您应该如何使用相机进行工作:
This is how you should do work involving your camera:
var cam = Camera.main;
if (cam != null)
{
// do something
}
这篇关于断言在表达式 go isactive () && 上失败go gettag() != 0 unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!