08-10-2018, Saat: 00:06
merhaba arkadaşlar. ben unity'nin öğrenme sayfasından object pooling script'ini aldım ve kendimce değiştirdim. şimdi ben bunun multiple olmasını istiyorum instantiate kısmı tamam ama skor'a göre obje sırası olmuyor. 50'den aşağı ise geniş yüksek ise orta 200'den yüksek ise dar olmasını istiyorum. bunun için kendim yazdım fakat çalışmadı bilen arkadaşlar yardımcı olabilirler mi acaba?
skor ne kadar yüksekse o kadar daralıcak.
skor ne kadar yüksekse o kadar daralıcak.
Kod:
public GameObject[] columnPrefab; //The column game object.
public int columnPoolSize = 5; //How many columns to keep on standby.
public static float spawnRate = 1.4f; //How quickly columns spawn.
public float columnMin = -1f; //Minimum y value of the column position.
public float columnMax = 3.5f; //Maximum y value of the column position.
private GameObject[] columns; //Collection of pooled columns.
private int currentColumn = 0; //Index of the current column in the collection.
private Vector2 objectPoolPosition = new Vector2(-15, -25); //A holding position for our unused columns offscreen.
public float spawnYPosition = 5f;
private float timeSinceLastSpawned;
[HideInInspector]
public int j;
void Start()
{
timeSinceLastSpawned = 0f;
//Initialize the columns collection.
columns = new GameObject[columnPoolSize];
//Loop through the collection...
for (int i = 0; i < columnPoolSize; i++)
{
//...and create the individual columns.
for (int k = 0; k < columnPrefab.Length; k++)
{
columns[i] = (GameObject)Instantiate(columnPrefab[k], objectPoolPosition, Quaternion.identity);
}
}
}
//This spawns columns as long as the game is not over.
void Update()
{
if (GameController.instance.score >= 50 && GameController.instance.score <= 149)
{
j = 1;
}
else if(GameController.instance.score >= 150)
{
j = 2;
}
else
{
j = 0;
}
timeSinceLastSpawned += Time.deltaTime;
if (GameController.instance.gameOver == false && timeSinceLastSpawned >= spawnRate)
{
timeSinceLastSpawned = 0f;
//Set a random y position for the column
float spawnXPosition = Random.Range(columnMin, columnMax);
//...then set the current column to that position.
columns[currentColumn].transform.position = new Vector2(spawnXPosition, spawnYPosition);
//Increase the value of currentColumn. If the new size is too big, set it back to zero
currentColumn++;
if (currentColumn >= columnPoolSize)
{
currentColumn = 0;
}
}
columnPrefab[j].transform.position = new Vector3(transform.position.x, transform.position.y, -.2f);
}