Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

object pooling on exact place?

$
0
0
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 :)

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>