using UnityEngine;
using System.Collections;
public class ObjectPool : MonoBehaviour
{
GameObject[] projectiles = null;
public int numberOfProjectilesToCreate = 0;
// Use this for initialization
void Start()
{
projectiles = new GameObject[numberOfProjectilesToCreate];
InstantiateProjectiles();
}
// Update is called once per frame
void Update()
{
{
ActivateProjectile();
}
}
private void InstantiateProjectiles()
{
for (int i = 0; i < numberOfProjectilesToCreate; i++)
{
projectiles[i] = Instantiate(Resources.Load("Prefab/PrefabCube")) as GameObject ;
projectiles[i].SetActiveRecursively(false);
}
}
private void ActivateProjectile()
{
for (int i = 0; i < numberOfProjectilesToCreate; i++)
{
if (projectiles[i].active == false)
{
projectiles[i].SetActiveRecursively(true);
projectiles[i].GetComponent().Activate();
return;
}
}
}
}
I used this and it is working...but i would like to make objects appear with exact distance between them so they don't overlap(even if speed is increased during runtime).
Any help would be great since I'm new to code.
Thx :)
↧