Ejemplo n.º 1
0
    public void SpawnFragments(Vector3 spawnPosition, AsteroidData asteroidData)
    {
        int fragmentCount = asteroidData.GetNumberOfFragments();

        if (fragmentCount > 0)
        {
            AsteroidData fragmentData = asteroidData.GetFragmentToSpawn();
            for (int i = 0; i < fragmentCount; i++)
            {
                SpawnAsteroid(spawnPosition, fragmentData);
            }
        }
        else
        {
            int activeAsteroids = 0;
            for (int i = 0; i < transform.childCount; i++)
            {
                GameObject child = transform.GetChild(i).gameObject;
                if (child.tag == GameManager.Instance.GetAsteroidTag() && child.activeInHierarchy)
                {
                    activeAsteroids++;
                    if (activeAsteroids > 1)
                    {
                        break;
                    }
                }
            }

            // only the asteroid being destroyed is active
            if (activeAsteroids == 1)
            {
                StartCoroutine(WaitToRespawn());
            }
        }
    }