当前位置:网站首页>UNITY gameobject代码中setacvtive(false)与面板中直接去掉勾 效果不一样
UNITY gameobject代码中setacvtive(false)与面板中直接去掉勾 效果不一样
2022-08-11 08:30:00 【hhkun0120】
也许看标题比较难懂,我要表达的是这个意思:
在hierarchy里面, UIroot下有个命名为MessageBox的panel,上面挂载着MessageBox脚本,脚本部分如下:
public class MessageBox : MonoBehaviour {
public static MessageBox _instance;
private TweenAlpha alphaTween;
private UILabel messageLabel;
private bool isActive = true;
void Awake(){
_instance = this;
alphaTween = this.GetComponent<TweenAlpha> ();
messageLabel = this.transform.Find ("bg/messageLabel").GetComponent<UILabel> ();
EventDelegate ed = new EventDelegate (this, "OnTweenFinished");
alphaTween.onFinished.Add (ed);
gameObject.SetActive (false);
}
public void ShowMessage(string message,float time){
gameObject.SetActive (true);
StartCoroutine(Show(message,time));
}
如果手动将hierarchy里的panel中inspector面板上的 勾去掉的话,外部用
MessageBox._instance
访问,会报错,空指针。
</pre><pre code_snippet_id="618972" snippet_file_name="blog_20150313_5_7730335" name="code" class="csharp">在要调用此对象的脚本中动态将其active设置为true
我猜测引起这个问题的原因是:
如果直接将hierarchy里的gameobject的勾去掉的话,unity引擎不会在初始的时候将这个gameobject"编译"。
我引用了其他语言中的编译的概念,我觉得比较贴近。
边栏推荐
猜你喜欢
js将table生成excel文件并去除表格中的多余tr(js去除表格中空的tr标签)
[C语言] sscanf如何实现sscanf_s?
Initial use of IDEA
Active users of mobile banking grew rapidly in June, hitting a half-year high
一根网线两台电脑传输文件
笔试题大疆08.07
Analysis of the Status Quo of Enterprise Server Host Reinforcement
Unity3D - modification of the Inspector panel of the custom class
万字长文带你了解多态的底层原理,这一篇就够了
LoRa芯片的特征
随机推荐
【Day_13 0509】▲跳石板
shell之sed
Rust从入门到精通06-函数
idea 方法注释:自定义修改method的return和params,void不显示
klayout--导出版图为gds文件
借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
查询跟踪快递单号物流,智能分析物流中转有延误的单号
redis operation
Kotlin算法入门求自由落体
pycharm中绘图,显示不了figure窗口的问题
2022年值得关注的NFT发展趋势
Project 1 - PM2.5 Forecast
兼容并蓄广纳百川,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang复合容器类型的声明和使用EP04
excel 透视表 值显示内容 不显示计数
C Primer Plus(6) 中文版 第1章 初识C语言 1.1 C语言的起源 1.2 选择C语言的理由 1.3 C语言的应用范围
IQUNIX A80 exploring TTC金粉 初体验
magical_spider远程采集方案
Nuget can't find the package problem
ImportError: /usr/local/cuda-11.2/lib64/libcublas.so.10: version `libcublas.so.10‘ not found
Pico neo3 Unity Packaging Settings