Hüseyin Şimşek
Hüseyin Şimşek

Reputation: 19

How to prevent to disable game object while game is running in Unity?

I am developing a simple game.I want to stay game object stable.However,While I am running game,game objects miss suddenly.How can I fix it?

Upvotes: 1

Views: 419

Answers (1)

vasmos
vasmos

Reputation: 2586

You should find out whats turning gameobjects off but you could try something like

void OnDisable() {
gameObject.SetActive(true); // Results in the error "Game Object is already being activated or deactivated
}

or

void OnDisable() {
StartCoroutine(ReEnable());
}

public IEnumerator ReEnable() {
yield return new WaitForSeconds(0.1f);
gameObject.SetActive(true);
}

Upvotes: 1

Related Questions