之前在网上搜了一些单例模式,使用的不是那么顺手,今天把自己感觉用得顺手的ts单例模式记录一下:
export default class PlayerController extends Laya.Script3D{
private static _inst: PlayerController;
public static get inst(): PlayerController {
if (this._inst == null) {
this._inst = new PlayerController();
}
return this._inst;
}
public is_over:boolean=false;
onAwake(){}
}
在其它地方调用:
var is_over=PlayerController.inst.is_over;