Hopefully anyone can help me out.
I have a some different prefabs and a script which spawn those objects. I has created an array of prefabs and manually placed them there. But after some time the amount of prefabs increased. What if I had a more objects (100-200) ?
How I have to find a right prefab and spawn it ? Public array of gameobjects in script will not be correct in this case (100 prefabs or more) ? What I have to do with this all objects? AssetBundles or Resource folder, which one will be correct ?
Objectpooling is best i think
public List m_pooledBullet;
public int m_PoolAmount;
void Start()
{
for(int i = 0 ; i<m_PoolAmount;i++)
{
GameObject obj = (GameObject)Instantiate(m_Bullet);
obj.SetActive(false);
m_pooledBullet.Add(obj);
}
}
public GameObject GetPooledBullet()
{
for(int i = 0 ; i<m_pooledBullet.Count;i++)
{
if(!m_pooledBullet*.activeInHierarchy)*
-
{*
return m_pooledBullet*;
_ }*_
* }*
* return null;*
* }*
* void Shoot()*
* {*
* GameObject obb = GetPooledBullet();*
* if(obb != null)*
* {*
* obb.transform.position = transform.position;*
* obb.transform.rotation = Quaternion.identity;*
* obb.gameObject.SetActive(true);*
* }*
* else*
* {*
* //Debug.Log(“null”);*
* }*
* }*