示例#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();
    }