当前位置:网站首页>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"编译"。
我引用了其他语言中的编译的概念,我觉得比较贴近。
边栏推荐
猜你喜欢
关于架构的认知
通过记账,了解当月收支情况
LoRa芯片的特征
框架外的PHP读取.env文件(php5.6、7.3可用版)
3.1-Classification-probabilistic generative model
go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
软件测试常用工具的用途及优缺点比较(详细)
Keep track of your monthly income and expenses through bookkeeping
租房小程序
进阶-指针
随机推荐
向日葵安装教程--向日葵远程桌面控制
链式编程注解
小程序组件不能修改ui组件样式
程序员是一碗青春饭吗?
优炫数据库支持多列分区吗?
通过记账,了解当月收支情况
mysql添加用户以及设置权限
3.1-Classification-probabilistic generative model
数据库无法启动,报无法分配内存,怎么处理
机器学习(三)多项式回归
WiFi cfg80211
9、Neural Sparse Voxel Fields
Alibaba Sentinel - Slot chain解析
Has legal counsel become a tasteless product of law firms?
为什么会没有内存了呢
FPGA 20个例程篇:11.USB2.0接收并回复CRC16位校验
One network cable to transfer files between two computers
流式结构化数据计算语言的进化与新选择
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
for循环和单击相应函数的执行顺序问题