Exemplo n.º 1
0
    // since spawning on OnDestroy() is dirty
    public override void Die()
    {
        if (isDying)
        {
            return;
        }
        isDying = true;

        AudioSource.PlayClipAtPoint(this.GetComponents <AudioSource>()[0].clip, transform.position);


        if (this.gameplay)
        {
            gameplay.addScore(this.scoreOnDeath);
        }

        if (this.spawnPrefab)
        {
            for (int i = 0; i < spawnCount; i++)
            {
                var spawn_pos = AsteroidsMathHelper.randomDirectionXZ() * Random.Range(0.0f, this.spawnRadius);
                var spawnling = (GameObject)Instantiate(spawnPrefab, this.transform.position + spawn_pos, Quaternion.identity);
                spawnling.GetComponent <Rigidbody>().velocity += this.GetComponent <Rigidbody>().velocity;

                var spawnling_wrap = spawnling.GetComponent <WarpingBehavior>();
                if (spawnling_wrap)
                {
                    spawnling_wrap.boundary = this.GetComponent <WarpingBehavior>().boundary;
                }
            }
        }

        base.Die();
    }
Exemplo n.º 2
0
    void spawnAsteroids()
    {
        if (isGameOver)
        {
            return;
        }

        currentDifficultyLevel += 1;
        if (currentDifficultyLevel >= difficulties.Count)
        {
            currentDifficultyLevel = difficulties.Count - 1;
        }

        int asteroidCount = Random.Range(difficulties[currentDifficultyLevel].minAsteroids
                                         , difficulties[currentDifficultyLevel].maxAsteroids);

        for (int i = 0; i < asteroidCount; i++)
        {
            var pos = Random.Range(10, 20) * AsteroidsMathHelper.randomDirectionXZ();

            if (playerShip)
            {
                pos += playerShip.transform.position;
            }

            GameObject ast         = (GameObject)Instantiate(asteroidsSpawnPrefab, pos, Quaternion.identity);
            var        ast_wraping = ast.GetComponent <WarpingBehavior>();
            if (ast_wraping)
            {
                ast_wraping.boundary = this.boundary;
            }
        }

        alienTimerRemaining = difficulties[currentDifficultyLevel].alienSpan;
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        var direction = AsteroidsMathHelper.randomDirectionXZ();

        this.GetComponent <Rigidbody>().velocity = direction * Random.Range(minSpawnSpeed, maxSpawnSpeed);

        this.rotationAxis = Random.onUnitSphere;
        this.GetComponent <Rigidbody>().rotation = Random.rotation;

        GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");

        if (gameControllerObject)
        {
            gameplay = gameControllerObject.GetComponent <GameplayLogic>();
        }
    }