示例#1
0
    void AddChildren()
    {
        if (size > 1)
        {
            //maybe rename to asteroidComponent later
            Asteroid ast;
            for (int i = 0; i < _asteroidInfo.targetChildCount; i++)
            {
                GameObject asteroid = Instantiate(_asteroidInfo.GetRandomAsteroidPrefab());

                //in case my teamates forget to add the asteroid script
                if (asteroid.GetComponent <Asteroid>())
                {
                    ast = asteroid.GetComponent <Asteroid>();
                }
                else
                {
                    Debug.LogError("ASTEROID SCRIPT NOT IS ON THE " + asteroid.name + " ASSET! fix it.");
                    ast = asteroid.AddComponent <Asteroid>();
                }

                ast.size = size - 1;
                AsteraX.AddAsteroid(asteroid.GetComponent <Asteroid>());

                Vector3 relPos = Random.onUnitSphere / 2;
                asteroid.transform.parent        = transform;
                asteroid.transform.rotation      = Random.rotation;
                asteroid.transform.localPosition = relPos;
                asteroid.transform.localScale    = Vector3.one * _asteroidInfo.scaleOffset;
                asteroid.name = gameObject.name + "_" + i.ToString("00");
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        AsteraX.AddAsteroid(this);

        transform.localScale = Vector3.one * size * AsteroidsScriptableObject.S.asteroidScale;
        if (parentIsAsteroid)
        {
            InitAsteroidChild();
        }
        else
        {
            InitAsteroidParent();
        }

        // Spawn child Asteroids
        if (size > 1)
        {
            Asteroid ast;
            for (int i = 0; i < AsteroidsScriptableObject.S.numSmallerAsteroidsToSpawn; i++)
            {
                ast      = SpawnAsteroid();
                ast.size = size - 1;
                ast.transform.SetParent(transform);
                Vector3 relPos = Random.onUnitSphere / 2;
                ast.transform.rotation      = Random.rotation;
                ast.transform.localPosition = relPos;

                ast.gameObject.name = gameObject.name + "_" + i.ToString("00");
            }
        }
    }
示例#3
0
    // Use this for initialization
    void Start()
    {
        if (asteroidSize == 0)
        {
            return;
        }

        AsteraX.AddAsteroid(this);

        transform.localScale = Vector3.one * asteroidSize * AsteraX.AsteroidsSO.asteroidScale;

        if (transform.parent == null)
        {
            InitializeParentAsteroid();
        }
        else
        {
            InitializeChildAsteroid();
        }

        if (asteroidSize > 1)
        {
            for (int i = 0; i < AsteraX.SubAsteroidsToSpawn; i++)
            {
                SpawnChildAsteroid(asteroidSize - 1, i);
            }
        }

        EventBroker.GameOver += DestroyMe;
    }