export default class GameLanch extends cc.Component {
onLoad() {
if (GameLanch.Instance === null) {
GameLanch.Instance = this;
}
else {
this.destroy();
return;
}
}
export default class GameLanch extends cc.Component {
onLoad() {
if (GameLanch.Instance === null) {
GameLanch.Instance = this;
}
else {
this.destroy();
return;
}
}
判断这个类的单例是否存在,不存在就创建,存在就销毁
这么写有啥用途吗,没想明白
因为单例一般只存在一个,所以没有的话就创建,有的话就不创建了,并且销毁当前的
明白了 是写在onLoad里的 