- Home /
Question by
AbdulRaman · Mar 23, 2018 at 01:09 PM ·
networkingnetworkspawnspawningsync
i'm trying to spawn enemies and it goes well but when i'm trying to scale them it doesn't sync i used [ClientRpc] and it didn't work
public GameObject EnemyPrefab;
public int numberOfEnemies;
public override void OnStartServer()
{
for (int i = 0; i < numberOfEnemies; i++)
{
Vector3 spawnPosstion = new Vector3(Random.Range(-8.0f, 8.0f), 0.0f, Random.Range(-8.0f, 8.0f));
Quaternion spawnRotation = Quaternion.Euler(0.0f, Random.Range(0.0f, 180f), 0.0f);
GameObject Enemy = Instantiate(EnemyPrefab, spawnPosstion, spawnRotation) as GameObject;
Enemy.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
NetworkServer.Spawn(Enemy);
}
}
Comment
Answer by hexagonius · Mar 24, 2018 at 11:04 AM
NetworkServer.Spawn only transfers the position. what you can do is create a script on the enemy with two SyncVar for rotation and scale. set these on the server before calling Spawn. use them in Awake or Start in the enemy to set him up.
i have been trying with this for a month can you please write the script
sorry, that's my daily work, that's enough for me.
finally i did it. but now i'm sticking in another problem i can't find a way how let the server spawns objects depending on screen size of each Clients