I have a method with a couple of overloads as different object types are expected (list vs array and GameObject vs ParticleSystem):
void ObjectLoop(int uBound, List<GameObject> list, GameObject item, bool projectile, int decalNo = 0, int typeNo = 0)
{
for (int x = 0; x < uBound; x++)
{
list.Add(Instantiate(item) as GameObject);
list[x].transform.SetParent(this.transform);
list[x].SetActive(false);
if (projectile)
{
projScript = list[x].GetComponent<J_Projectile>();
projScript.decalType = decalNo;
projScript.hitType = typeNo;
}
}
}
void ObjectLoop(int uBound, List<ParticleSystem> list, ParticleSystem item)
{
for (int x = 0; x < uBound; x++)
{
list.Add(Instantiate(item) as ParticleSystem);
list[x].transform.SetParent(this.transform);
list[x].gameObject.SetActive(false);
}
}
void ObjectLoop(int uBound, GameObject[] list, GameObject item)
{
for (int x = 0; x < uBound; x++)
{
list[x] = (Instantiate(fireHazard) as GameObject);
list[x].transform.SetParent(this.transform);
list[x].SetActive(false);
}
}
Is there any way to condense these into a single method, perhaps by passing the object types for list or array and GameObject or ParticleSystem? I'm guessing it has something to do with generics but I can't quite get my head around it so an explanation for dummies would be welcome :)
Thanks