当前位置:网站首页>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"编译"。我引用了其他语言中的编译的概念,我觉得比较贴近。边栏推荐
- Active users of mobile banking grew rapidly in June, hitting a half-year high
- 向日葵安装教程--向日葵远程桌面控制
- 基础SQL——DDL
- 3.1-Classification-probabilistic generative model
- WiFi cfg80211
- 2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号 0 的弹簧处。若小球在编号为 i 的弹
- Find the latest staff salary and the last staff salary changes
- js将table生成excel文件并去除表格中的多余tr(js去除表格中空的tr标签)
- leetcode: 69. Square root of x
- 记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.
猜你喜欢

囍楽cloud task source code

dsu on tree(树上启发式合并)学习笔记

机器学习(一)数据的预处理

Keep track of your monthly income and expenses through bookkeeping
几何EX3 功夫牛宣布停售,入门级纯电产品为何总成弃子

Notable NFT development trends in 2022

excel将数据按某一列值分组并绘制分组折线图

基础SQL——DDL

Unity3D——自定义类的Inspector面板的修改

2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号 0 的弹簧处。若小球在编号为 i 的弹
随机推荐
【Day_13 0509】▲跳石板
gRPC系列(四) 框架如何赋能分布式系统
go sqlx 包
redis operation
Kotlin算法入门求回文数算法优化一
Kotlin Algorithm Getting Started with Rabbit Number Optimization and Expansion
【实战系列】OpenApi设计规范
Getting Started with Kotlin Algorithms Calculating Prime Numbers and Optimization
几何EX3 功夫牛宣布停售,入门级纯电产品为何总成弃子
快速幂,逆元的求解
Kotlin算法入门计算水仙花数
Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
CIKM 2022 AnalytiCup Competition: Federal Heterogeneous Task Learning
go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
剑指offer专项突击版第26天
Nuget can't find the package problem
Kotlin算法入门兔子数量优化及拓展
@RequiredArgsConstructor注解
如何仅更改 QGroupBox 标题的字体?
选择收银系统主要看哪些方面?