- Home /
Creating a reference gameobject of a prefab
What I want to do is fill up a new gameobject with all the data I want for future use, without generating a prefab. I fill it up with material information and a single cube prefab information.
Here's my code public GameObject CreateItem_BlockJunk() { GameObject block_Mat = new GameObject(); block_Mat = Resources.Load("prefabs/block") as GameObject; block_Mat.renderer.material = Resources.Load("materials/junk") as Material;
return block_Mat;
}
public GameObject CreateItem_BlockWood()
{
GameObject block_Mat = new GameObject();
block_Mat = Resources.Load("prefabs/block") as GameObject;
block_Mat.renderer.material = Resources.Load("materials/wood") as Material;
return block_Mat;
}
public GameObject CreateItem_BlockBrick()
{
GameObject block_Mat = new GameObject();
block_Mat = Resources.Load("prefabs/block") as GameObject;
block_Mat.renderer.material = Resources.Load("materials/brick") as Material;
return block_Mat;
}
public GameObject CreateItem_BlockStone()
{
GameObject block_Mat = new GameObject();
block_Mat = Resources.Load("prefabs/block") as GameObject;
block_Mat.renderer.material = Resources.Load("materials/stone") as Material;
return block_Mat;
}
public GameObject CreateItem_BlockMetal()
{
GameObject block_Mat = new GameObject();
block_Mat = Resources.Load("prefabs/block") as GameObject;
block_Mat.renderer.material = Resources.Load("materials/metal") as Material;
return block_Mat;
}
public GameObject CreateItem_BlockRadium()
{
GameObject block_Mat = new GameObject();
block_Mat = Resources.Load("prefabs/block") as GameObject;
block_Mat.renderer.material = Resources.Load("materials/radium") as Material;
return block_Mat;
}
void Awake()
{
Items = new GameObject[10];
Items[0] = CreateItem_BlockJunk();
Items[1] = CreateItem_BlockWood();
Items[2] = CreateItem_BlockBrick();
Items[3] = CreateItem_BlockStone();
Items[4] = CreateItem_BlockMetal();
Items[5] = CreateItem_BlockRadium();
Items[6] = null;
Items[7] = null;
Items[8] = null;
Items[9] = null;
}
Now the problem is is that Items[0] - Items[5] all return the same last object which was CreateItem_BlockRadium(); I was able to fix this by adding instantiate but that created an actual object in the world and I didn't want to do that. I just want to fill up a gameobject and use it for future reference. Is this possible without instantiating? Am I missing something?