コード例 #1
0
 void AsteroidChunkSetup()
 {
     if (!setup)
     {
         // generate a random vector to use for velocity and rotation
         randomVector   = (Vector3.left * (Random.Range(-1, 1) + .1f) + Vector3.forward * (Random.Range(-1, 1) + .1f)).normalized;
         randomVector.y = 0;
         // not childed to main asteroid any more
         transform.parent = null;
         // tell previous parent that this asteroid is gone
         if (mainAsteroid)
         {
             mainAsteroid.RemoveChunk(this);
             mainAsteroid.rb.AddTorque(mainAsteroid.randomVector + randomVector * (mainAsteroid.asteroidSize == AsteroidSize.Big ? 100 : 50));
             rotationVector = mainAsteroid.rb.angularVelocity;
         }
         maxMoveSpeed  = Random.Range(maxMoveSpeed / 2, maxMoveSpeed);
         rotationSpeed = Random.Range(rotationSpeed / 2, rotationSpeed);
         mainAsteroid  = null;
         GetComponent <WrapObject>().enabled = true;
         Instantiate(particleTrail, transform);
         // add points and add chunk to wave manager
         GameManager.gm.AddPoints(GameManager.PointEvent.chunkHit);
         setup = true;
     }
 }
コード例 #2
0
    public void SpawnWave()
    {
        if (allWaves.Count > 0)
        {
            asteroidsRemaining.Clear();
            chunksRemaining.Clear();

            // Instantiate big asteroids
            for (int i = 0; i < allWaves[0].bigCount; i++)
            {
                spawnedAsteroid = Instantiate(asteroidPrefabsBig[Random.Range(0, asteroidPrefabsBig.Length)]);
                spawnedAsteroid.transform.position = ChooseAsteroidSpawnLocation();
                spawnedAsteroid.AsteroidInteraction();
                asteroidsRemaining.Add(spawnedAsteroid);
            }

            // Instantiate huge asteroids
            for (int i = 0; i < allWaves[0].hugeCount; i++)
            {
                spawnedAsteroid = Instantiate(asteroidPrefabsHuge[Random.Range(0, asteroidPrefabsHuge.Length)]);
                spawnedAsteroid.transform.position = ChooseAsteroidSpawnLocation();
                spawnedAsteroid.AsteroidInteraction();
                asteroidsRemaining.Add(spawnedAsteroid);
            }

            allWaves.RemoveAt(0);
        }

        spawning = false;
    }
コード例 #3
0
    public void RemoveAsteroid(AsteroidBig _ast)
    {
        asteroidsRemaining.Remove(_ast);

        // if no asteroids or chunks left, move to next wave
        if (!spawning && asteroidsRemaining.Count == 0 && chunksRemaining.Count == 0)
        {
            spawning = true;
            SpawnWave();
        }
    }
コード例 #4
0
    void OnTriggerEnter2D(Collider2D col)
    {
        Enemy_Laser    eLaser = col.gameObject.GetComponent <Enemy_Laser> ();
        TurretBehavior turret = col.gameObject.GetComponent <TurretBehavior> ();
        AsteroidBig    big    = col.gameObject.GetComponent <AsteroidBig> ();
        AsteroidMed    med    = col.gameObject.GetComponent <AsteroidMed> ();
        AsteroidSmall  small  = col.gameObject.GetComponent <AsteroidSmall> ();

        if (eLaser)
        {
            eLaser.Hit();
            Destroy(gameObject);
            AudioSource.PlayClipAtPoint(destroyed, this.transform.position);
            Instantiate(debris, this.transform.position, Quaternion.identity);
        }

        if (big || med || small || turret || col.tag == "Wall")
        {
            Destroy(gameObject);
            AudioSource.PlayClipAtPoint(destroyed, this.transform.position);
            Instantiate(debris, this.transform.position, Quaternion.identity);
        }
    }