예제 #1
0
    private void SpawnAsteroid()
    {
        Vector3            position = new Vector3(Random.Range(spawnRect.xMin, spawnRect.xMax), Random.Range(spawnRect.yMin, spawnRect.yMax), 0);
        AsteroidController asteroid = PoolManager.instance.GetFreeObject(position) as AsteroidController;

        if (asteroid != null)
        {
            float   angle    = Random.Range(asteroidMinAngle, asteroidMaxAngle) * Mathf.PI / 180;
            Vector3 velocity = new Vector3(Mathf.Cos(angle) * asteroidVelocity, Mathf.Sin(angle) * asteroidVelocity, 0);
            float   scale    = Random.Range(asteroidMinScale, asteroidMaxScale);
            asteroid.Init(velocity, scale);
            asteroid.OnAsteroidCollect = OnAsteroidCollect;
            asteroid.OnAsteroidStrike  = OnAsteroidStrike;
        }
    }
예제 #2
0
    private void SpawnAsteroid(Vector3 spawnPosition, AsteroidData asteroidData)
    {
        GameObject asteroid = PoolsManager.Instance.GetAsteroidsPool().GetAvailable();

        asteroid.transform.position = spawnPosition;
        asteroid.transform.rotation = Random.rotation;

        asteroid.SetActive(true);

        Rigidbody asteroidRB = asteroid.GetComponent <Rigidbody>();

        asteroidRB.mass = asteroidData.GetMass();
        RandomSpacePusher randomPusher = asteroid.GetComponent <RandomSpacePusher>();

        randomPusher.SetRandomPush(pushForce, angularVelocity);
        randomPusher.GivePush();
        AsteroidController asteroidController = asteroid.GetComponent <AsteroidController>();

        asteroidController.Init(asteroidData);
    }
예제 #3
0
    /// <summary>
    /// Create a new asteroid into scene
    /// </summary>
    /// <param name="type">asteroid type</param>
    /// <param name="pos">asteroid spawn position (spawn position index)</param>
    /// <returns></returns>
    public GameObject Create(int type, int pos = -1)
    {
        AsteroidController asteroids = GameObject.Instantiate(prefabs[type]).GetComponent <AsteroidController>();

        asteroids.Init(manager);

        if (type < 2)
        {
            smallAsteroids.Add(asteroids.gameObject);
        }

        if (pos >= 0)
        {
            asteroids.gameObject.SetActive(true);
            asteroids.instance.Activate(spawnPos[pos]);

            return(asteroids.gameObject);
        }

        asteroids.gameObject.SetActive(false);
        return(asteroids.gameObject);
    }