Ejemplo n.º 1
0
    void SpawnAsteroidInRingAtAngle(PlanetaryRing ring, float spawnAngleRelToLocalX)
    {
        // where to spawn in the next asteroid
        float nextSize = Random.Range(ring.sizeScaleMedian - ring.sizeScaleVariance, ring.sizeScaleMedian + ring.sizeScaleVariance);

        if (nextSize == 0)
        {
            return;
        }
        float   nextDistance         = Random.Range(ring.minDistance, ring.maxDistance);
        Vector3 nextAsteroidPosition = new Vector2(Mathf.Cos(spawnAngleRelToLocalX), Mathf.Sin(spawnAngleRelToLocalX)) * nextDistance;

        // spawn it in
        GameObject nextAsteroid = SimplePool.Spawn(ring.AsteroidPrefab, nextAsteroidPosition, Quaternion.identity);

        // set initial conditions
        nextAsteroid.transform.parent     = transform;
        nextAsteroid.transform.localScale = new Vector3(nextSize, nextSize, 1);
        float nextSpeed = Random.Range(ring.speedMedian - ring.speedVariance, ring.speedMedian + ring.speedVariance);

        nextAsteroid.GetComponent <Rigidbody2D>().velocity = transform.up * nextSpeed;
    }
Ejemplo n.º 2
0
 void CheckPlanetaryRing(PlanetaryRing ring)
 {
     // we don't want non-sense values
     if (ring.asteroidCount < 0)
     {
         ring.asteroidCount = 0;
     }
     if (ring.frequency < 0f)
     {
         ring.frequency = 0f;
     }
     if (ring.minDistance < 10f)
     {
         ring.minDistance = 10f;
     }
     if (ring.maxDistance < 10f)
     {
         ring.maxDistance = 10f;
     }
     if (ring.maxDistance < ring.minDistance)
     {
         float temp = ring.minDistance;
         ring.minDistance = ring.maxDistance;
         ring.maxDistance = temp;
     }
     if (ring.sizeScaleMedian < 0)
     {
         ring.sizeScaleMedian = 0;
     }
     if (ring.sizeScaleMedian - ring.sizeScaleVariance < 0)
     {
         ring.sizeScaleVariance = ring.sizeScaleMedian;
     }
     if (ring.speedMedian - ring.speedVariance < 0)
     {
         ring.speedVariance = ring.speedMedian;
     }
 }