Hello, I am creating a new Game Object from a prefab, with Instantiate() method. However, whenever try to access a property of the object I created, it seems to be null. So for example what is the best way to create a instantiate a gameobject and change its name to something else right after. My code is here:
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
spawnPos = new Vector3(brickPiece.renderer.bounds.size.x*x,brickPiece.renderer.bounds.size.y*y,0);
GameObject newObj = new GameObject();
newObj = (Instantiate( brickPiece, spawnPos, Quaternion.identity)) as GameObject;
newObj.name = "brick "+(5*y+x); // can not change cuz newObj seems null
}
}