Error with Object Sync

Options
Hellos guys,

i hope my english is good enough to describe what my problem is :dizzy:

In my game i want to randomly place object (ground tiles). It works fine with the Hostclient. But when i connect to the server with another client, the positions of those spawned ground tiles are not correct. The objects will be placed, but not in the right positions and i dont know why. Can anybody help me? :)



ScreenshotURL: http://img5.fotos-hochladen.net/uploads/photon41ce6op5wy.png

Code:

using UnityEngine;
using System.Collections;


public class TestScript : Photon.MonoBehaviour {

public GameObject[] prefabs;

GameObject GroundTile;

void OnJoinedRoom()
{
if (PhotonNetwork.isMasterClient != false) {
Debug.Log (PhotonNetwork.isMasterClient);
bool lastTileWasRoad = false;
Vector3 pos = Vector3.zero;
for (int i = 0; i < 5; i++) {
int idx;
GameObject prefabToSpawn;
do {
idx = Random.Range (0, prefabs.Length);
prefabToSpawn = prefabs [idx];
} while (lastTileWasRoad && prefabToSpawn.tag == "Road");

GameObject g = PhotonNetwork.InstantiateSceneObject (prefabToSpawn.name, Vector3.zero, Quaternion.identity, 0, null) as GameObject;

//GameObject g = Instantiate(prefabToSpawn, Vector3.zero, Quaternion.identity) as GameObject;
g.transform.parent = transform;

g.transform.localPosition = pos;

// Spawner sp = g.GetComponentInChildren();
// if (sp)
// sp.carCount = Random.Range(2, 9);


pos += Vector3.forward * g.transform.GetChild (0).transform.localScale.z;

if (g.tag == "Road")
lastTileWasRoad = true;
else
lastTileWasRoad = false;
}
}
}
// Use this for initialization
void Start () {


}

// Update is called once per frame
void Update () {

}


}

Comments

  • xnitro
    Options
    never mind...found my mistake. I had to turn off my Photon Transform View :)