Hi,
I just finished changes in my codes to to be able use .Create and also parent objects in correct objects.
Code for .Create:
public static int terrain_i;
public static int vegetation_i;
public static GameObject[] ter_position;
public static GameObject[] veg_position;
void Start (){
ter_position = GameObject.FindGameObjectsWithTag("ter_position");
for (var i =0; i < ter_position.Length; i ++){
terrain_i = i;
TNManager.Create (terrains [Random.Range (0, terrains.Length)], ter_position[i].transform.position, ter_position[i].transform.rotation);
}
veg_position = GameObject.FindGameObjectsWithTag("position");
for (var i = 0; i < veg_position.Length; i++) {
vegetation_i = i;
TNManager.Create (vegetation [Random.Range (0, vegetation.Length)], veg_position[i].transform.position, veg_position[i].transform.rotation);
}
}
and code for parenting:
void Awake () {
transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent;
transform
.localScale = new Vector3
(0
.0078f, 0
.0078f, 0
.0078f
); }
Both scripts works great when Iam using scene without menu that mean when I just hit play scene in editor - objects are created and moved as a childs to corrects objects and they are resized.
Problem is when Iam using this with start server, join,... For test Iam using your example main menu scene, I was added my scene to Example Menu script in inspector also I added all object that are .Created to TNManager. When I start server(local host for me) and chose my scene from selection, my scene is loaded I see it for about 1second and then is scene switched to Main Menu where I can connect to IP or stop server. After this I have just one error: NullReferenceException: Object reference not set to an instance of an object
terrain_set.Awake () (at Assets/Scripts/World/Basic/terrain_set.cs:7)
which is reference to this line:
transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent;
I dont really know what is wrong with that or why my scene drop to main menu every time. I have this problem also when I use if(!TNManager.isHosting)return; in my .Create script. When Iam not using my .Create script - Iam deactivate that script - so no terrain and vegetation is created I dont have this problem I can walking around in game with no problem.
I hope you understand me. Thank you for your time.
PS.: How to make players? I know I probably need to .Create player prefab when player is joined to game but which script must be on player object, how to synchronize move or how to set owner of this object to be able move with.