Hey guys,
i have read some answeres about that but no one works for me.
I tried to create several objects and set their parent. But it seems like the objects are not created when i try to set the transform.parent value
This is my code:
void OnWizardCreate()
{
GameObject parentObj = new GameObject();
parentObj.name = roomName;
if (!parentObj)
{
Debug.Log("parentObj is not existing yet");
}
else
{
for (x = 0; x < roomWidthX; x++)
{
for (z = 0; z < roomWidthZ; z++)
{
GameObject temp = GameObject.Instantiate(tile, new Vector3(x + startPosition.x, startPosition.y, z + startPosition.z), Quaternion.identity) as GameObject;
if (temp == null)
{
Debug.Log("temp is not existing yet");
}
else
{
temp.transform.parent = parentObj.transform;
}
}
}
}
when i start this function the console throws that the temp Object is not yet existing.
If i do that without the if(temp == null) part then i get a Null Reference exception.
Any ideas on what could solve my problems are very welcome!
How is 'tile' defined and initialized?
– robertbupublic Transform tile; i set it in unity and its a normal gameobject
– Pascal1234