当前位置:网站首页>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"编译"。
我引用了其他语言中的编译的概念,我觉得比较贴近。
边栏推荐
- 2022 China Soft Drink Market Insights
- go 操作MySQL之mysql包
- [C语言] sscanf如何实现sscanf_s?
- 经典论文-MobileNet V1论文及实践
- Unity3D——自定义类的Inspector面板的修改
- 流式结构化数据计算语言的进化与新选择
- Getting Started with Kotlin Algorithms Calculating Prime Numbers and Optimization
- For the first time, I suspect that there is a bug in selenium4 because the iframe element is not found?
- 如何通过开源数据库管理工具 DBeaver 连接 TDengine
- C Primer Plus(6) 中文版 第1章 初识C语言 1.1 C语言的起源 1.2 选择C语言的理由 1.3 C语言的应用范围
猜你喜欢
随机推荐
企业服务器主机加固现状分析
Kotlin算法入门计算质因数
《剑指offer》题解——week3(持续更新)
向日葵安装教程--向日葵远程桌面控制
Getting Started with Kotlin Algorithm to Calculate the Number of Daffodils
万字长文带你了解多态的底层原理,这一篇就够了
Interaction of Pico neo3 in Unity
Getting Started with Kotlin Algorithms Calculating Prime Factors
机器学习(二)线性回归
2022年值得关注的NFT发展趋势
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
通过记账,了解当月收支情况
Kali penetration test environment set up
[C语言] sscanf如何实现sscanf_s?
小目标检测3_注意力机制_Self-Attention
CIKM 2022 AnalytiCup Competition: Federal Heterogeneous Task Learning
idea 方法注释:自定义修改method的return和params,void不显示
美术2.4 UV原理基础
One network cable to transfer files between two computers
picker选择器出现object解决办法