title: C# / Unity3d - pass object type as parameter
body: <p>I have a method with a couple of overloads as different object types are expected (list vs array and GameObject vs ParticleSystem):</p>
  
  <pre><code>void ObjectLoop(int uBound, List&lt;GameObject&gt; list, GameObject item, bool projectile, int decalNo = 0, int typeNo = 0)
  {
      for (int x = 0; x &lt; uBound; x++)
      {
          list.Add(Instantiate(item) as GameObject);
          list[x].transform.SetParent(this.transform);
          list[x].SetActive(false);
          if (projectile)
          {
              projScript = list[x].GetComponent&lt;J_Projectile&gt;();
              projScript.decalType = decalNo;
              projScript.hitType = typeNo;
          }
      }
  }
  
  void ObjectLoop(int uBound, List&lt;ParticleSystem&gt; list, ParticleSystem item)
  {
      for (int x = 0; x &lt; 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 &lt; uBound; x++)
      {
          list[x] = (Instantiate(fireHazard) as GameObject);
          list[x].transform.SetParent(this.transform);
          list[x].SetActive(false);
      }
  }
  </code></pre>
  
  <p>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 :)</p>
  
  <p>Thanks</p>