Y
Y
yraiv2020-01-02 15:29:08
Unity
yraiv, 2020-01-02 15:29:08

On the Dontdestroy object, how to make only 1 object when returning to the scene?

I have DontDestroyOnLoad on the object, but when I launch others and scenes and then come back, I already have 2 objects, if I go out again and go to the scene where the object was originally, then there will be even more of them by 1. How can I to make a restriction so that no more than 1 object could exist?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2020-01-02
@yraiv

var dd = GameObject.FindGameObjectsWithTag("DONT_DESTROY");
if (dd.Length > 1)
{
    Destroy(this.gameObject);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question