I have a random world with some trees that get randomly instantiated.
I use the following code to instantiate them:
GameObject go = Instantiate(treePrefab);
go.name = "Tree";
go.tag = "Wood";
go.layer = 9;
go.transform.position = new Vector3(y + UnityEngine.Random.Range(-0.5f, 0.5f), heightPos, x + UnityEngine.Random.Range(-0.5f, 0.5f));
go.transform.Rotate(0, UnityEngine.Random.Range(0, 360), 0);
x
and y
are part of a for loop that goes through all positions (like a grid) of my world.
heightPos
is the current height of the terrain at the specific point (x/y).
My problem is that the prefab ob the trees has the position 0, 0, 0.
Every tree that get's instantiated gets set to 0, 0, 0 too.
I use the exact same code to instantiate rocks, cactus, feathers, car's and many other things, and it works perfect.
but it always fails at the trees.
I've looked through the code and there is no difference to the other objects, except the prefab (of course).
So i think it has to do something with the settings of the prefab.
But my prefab got no animator, it is not static or something.
This is what my tree-Prefab looks like in the inspector:
and this is what it looks like in scene view: