我在Unity编码,我发现即使游戏对象被销毁,有时一个方法也可以通过Invoke函数调用。 这就是为什么我添加了这个检查,它似乎工作正常,但它很奇怪。
让我们说我有一个物体,我想在一秒钟内自我毁灭。 我在Awake中添加一个Invoke来自我毁灭它。 而且,如果游戏结束,我想立即销毁游戏对象。该对象订阅了Gameover事件。
void Awake ()
{
Invoke ("_destroy", 1);
GameMachine.Gameover += _destroy;
}
_destroy方法是这样的:
void _destroy()
{
if (!this) {
return;
}
GameMachine.Gameover -= _destroy;
Destroy (this.gameObject);
}
我已经补充说,如果(!this)检查,因为我发现Invoke可以到达_destroy方法,即使该对象已被游戏事件摧毁。 这有任何意义,是否有可能发生?
由于
答案 0 :(得分:0)
据我所知,它会起作用,但是,这样做并不是一个好主意。 Unity的MonoBehaviour会覆盖bool运算符。因此,检查时
/* POST */
function authenticate(Request $request) {
$username = $request->input('username');
$password = $request->input('password');
if(Auth::attempt(['username' => $username, 'password' => $password])) {
redirect()->route('home'); /* should redirect to player */
}
return response()->json(['error' => trans('errors.user_password_combination').' => '.$username.' & '.$password]);
}
您正在检查对象(以及脚本)是否存在。
作为旁注,如果您要取消订阅活动,请改用OnDisable功能。代码示例
!this