コード例 #1
0
    public void divideAsteroid()
    {
        if (explosionTimer > 0)
        {
            return;
        }
        Rigidbody astExp = (Rigidbody)Instantiate(asteroidExplosion, transform.position, transform.rotation);

        astExp.velocity = rigidBody.velocity;
        if (size < 3)
        {
            Rigidbody      newAsteroid1    = (Rigidbody)Instantiate(asteroid, transform.position, transform.rotation);
            asteroidScript newAsteroid1Scr = newAsteroid1.GetComponent <asteroidScript>();
            newAsteroid1Scr.newAsteroid();
            newAsteroid1Scr.setSize(size + 1);
            newAsteroid1Scr.setPosition(newPos1.position);
            newAsteroid1Scr.setMass(rigidBody.mass / 2);
            newAsteroid1Scr.setExplosionTimer();
            asteroidSpawner.incAsteroidCount();
            Rigidbody      newAsteroid2    = (Rigidbody)Instantiate(asteroid, transform.position, transform.rotation);
            asteroidScript newAsteroid2Scr = newAsteroid2.GetComponent <asteroidScript>();
            newAsteroid2Scr.newAsteroid();
            newAsteroid2Scr.setSize(size + 1);
            newAsteroid2Scr.setPosition(newPos2.position);
            newAsteroid2Scr.setMass(rigidBody.mass / 2);
            newAsteroid2Scr.setExplosionTimer();
            asteroidSpawner.incAsteroidCount();

            newAsteroid1.AddExplosionForce(1000.0f, transform.position, expRadius, 5.0f);
            newAsteroid1Scr.setVelocity(newAsteroid1.velocity + rigidBody.velocity);
            newAsteroid2.AddExplosionForce(1000.0f, transform.position, expRadius, 5.0f);
            newAsteroid1Scr.setVelocity(newAsteroid2.velocity + rigidBody.velocity);
        }
        Destroy(gameObject);
        asteroidSpawner.decAsteroidCount();
    }