hello everyone! actually i have a working code to spawn my prefabs object on the 2D fields, but looks using too much memory, when i install it on iphone i’m getting a low frame rate on the first second of the game, so should be this part of code, someone know a different way to do the same things?
sorry for my bad English.
public int CoinPoolSize = 20;
public float spawnRate = 2f;
public GameObject coinPrefabs;
public float coinMin = -6f;
public float coinMax = 10f;
private GameObject[] coin;
private Vector2 coinPoolPosition = new Vector2(-15f,-25f);
private float timeSinceLastSpawned;
private float spawnXposition = 10f;
private int currentCoin = 0;
// Use this for initialization
void Start ()
{
coin = new GameObject[CoinPoolSize];
for(int i = 0; i < CoinPoolSize; i++)
{
coin [i] = (GameObject)Instantiate (coinPrefabs, coinPoolPosition, Quaternion.identity);
}
}
// Update is called once per frame
void Update ()
{
timeSinceLastSpawned += Time.deltaTime;
if(GameControl.instance.gameOver == false && timeSinceLastSpawned >= spawnRate)
{
timeSinceLastSpawned = 0;
float spawnYposition = Random.Range(coinMin,coinMax);
coin [currentCoin].transform.position = new Vector2(spawnXposition, spawnYposition);
currentCoin ++;
if(currentCoin >= 20)
{
currentCoin = 0;
}
}
}