Beispiel #1
0
    private void SpawnEnemy()
    {
        positionToSpawn side = (positionToSpawn)Random.Range(0, 3);
        Vector3         pos  = Vector3.zero;

        switch (side)
        {
        case positionToSpawn.Up:
            pos = new Vector3(Random.Range(minX, maxX), maxY, 0.0f);
            break;

        case positionToSpawn.Down:
            pos = new Vector3(Random.Range(minX, maxX), minY, 0.0f);
            break;

        case positionToSpawn.Right:
            pos = new Vector3(maxX, Random.Range(minY, maxX), 0.0f);
            break;

        case positionToSpawn.Left:
            pos = new Vector3(minX, Random.Range(minY, maxX), 0.0f);
            break;
        }

        GameObject obj = enemyPool.GetObjectFromPool();

        if (obj)
        {
            obj.SetActive(true);
            obj.transform.position = pos;
        }
    }