I’ve read all topics about networking , but still have not found a solution for this someone could help me ?
Basically what I want is to spawn different monsters in different positions and rotations in server , and all clients sync them.
Components on Object to spawn:
in case image dont show : Imgur: The magic of the Internet.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class EnemySpawner: NetworkBehaviour
{
public GameObject[] monsterType;
GameObject[] monsterInstantiate;
int randomizer;
public override void OnStartServer()
{
monsterInstantiate = new GameObject[10];
StartSpawner ();
}
void StartSpawner()
{
for(int i = 0; i < 10; i++)
{
Vector3 Pos = new Vector3 (Random.Range (-30, 30), 0, Random.Range (-30, 30));
Quaternion Rot = Quaternion.Euler (new Vector3 (0, Random.Range (0f, 360F), 0));
randomizer = Random.Range (0, 9);
monsterInstantiate[i] = (GameObject)Instantiate (monsterType[randomizer], Pos, Rot);
NetworkServer.Spawn (monsterInstantiate[i]);
}
}
}