コード例 #1
0
ファイル: Asteroid.cs プロジェクト: amatt1552/AsteraX
    //should probably change so that it adds the score and such on Achievements or AsteraX
    /// <summary>
    /// Handles destruction of the Asteroid when its hit
    /// </summary>
    /// <param name="collision"></param>
    public void AsteroidHit(Collision collision)
    {
        int childCount = transform.childCount;
        //getting position before destroying the bullet
        Vector3 collisionPosition = collision.transform.position;

        //updates score and destroys bullet
        if (collision.gameObject.GetComponent <Bullet>())
        {
            //the score seemed to be like binary so thought I'd just calculate for any size if the player didn't die already.
            //added more to score while dead so fixed that.
            if (!AsteraX.DEAD)
            {
                playerController.AddPoints((int)Mathf.Pow(2, _asteroidInfo.size - size) * 100);
                Achievements.ASTEROIDS_HIT++;

                Achievements.AchievementCheck();
                if (collision.gameObject.GetComponent <Bullet>().bulletWrapped)
                {
                    Achievements.BULLET_WRAP_COUNT++;
                    Achievements.AchievementCheck();
                }
            }
            UIScript.UpdateScore(playerController.GetScore());
            Destroy(collision.gameObject);
        }

        for (int i = 0; i < childCount; i++)
        {
            Transform child = transform.GetChild(0);
            child.SetParent(null, true);

            if (child.GetComponent <Asteroid>())
            {
                Asteroid asteroidComp = child.GetComponent <Asteroid>();
                asteroidComp.EnableRB();
                asteroidComp.AddForceFromPoint(collisionPosition, Random.Range(_asteroidInfo.minVelocity, _asteroidInfo.maxVelocity));
                asteroidComp.AddAngularVelocity(Random.insideUnitSphere * _asteroidInfo.maxAngularVelocity);
            }
        }

        //dont need to check for get component since this is the component its looking for.
        AsteraX.RemoveAsteroid(this);
        //starts onDestroy Event
        onDestroy.Invoke();
        AsteraX.ExplosionEffect(transform, size);
        //destroys this asteroid
#if MOBILE_INPUT
        foreach (GameObject col in compoundColliders)
        {
            Destroy(col);
        }
#endif
        Destroy(gameObject);
    }