Unity 2D Instantiating a prefab with it's components
- by TazmanNZL
I have some block prefabs that I add to an array of game objects:
public GameObject[]blocks;
Each prefab has a BoxCollider2D, Script & Rigidbody2D components. But when I try to instantiate the prefab in the scene it doesn't appear to have the components attached?
Here is how I am instantiating the prefab:
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < gridWidth; j++)
{
blockClone = Instantiate (blocks [Random.Range (0, blocks.Length)] as GameObject, new Vector3 (j, -i-2, 0f), transform.rotation) as GameObject;
}
}
What am I doing wrong?