- Home /
If GameObject with tags not on scene
I work Unity 4.3. I have coins object on scene. They have tags: ,,Coin". (These are prefab) I will make this: if all ,,Coin" tagged object destroyed on scene, then activate Level2. How can I make this? I have this code in a simple GameObject on scene, but does not work. If play scene, all tagged coin in scene, but the level2 activated...
if ( GameObject.FindWithTag("Coin") !=null)
{
Application.LoadLevel ("Level2");
}
This does not work too:
if ( GameObject.FindGameObjectsWithTag("Coin") !=null)
{
Application.LoadLevel ("Level2");
}
Answer by robertbu · May 03, 2014 at 02:34 PM
Try this:
if ( GameObject.FindGameObjectsWithTag("Coin").Length == 0)
{
Application.LoadLevel ("Level2");
}
You cannot use a null check because FindGameOjectsWithTag() always returns an array. It just will be empty if it does not find anything.
Or alternately you can do:
if ( GameObject.FindWithTag("Coin") == null)
{
Application.LoadLevel ("Level2");
}
FindWithTag() returns the first one found, so null check will work here.
Thank You! I made it with function Update () and it's work!
Your answer
Follow this Question
Related Questions
FindGameObjectsWithTag check gameObject disabled? 1 Answer
How to set a game-over scene when an object hits another? 0 Answers
i want the player to match 5 items correctly before next scene appears. 1 Answer
Find an object in a new scene that hasn't been destroyed? 4 Answers
Find how many are there in the scene 1 Answer