I haven’t been able to figure this one out. From everything that I have read so far Network.Instantiate should create a prefab on everyone(server and client). Unfortunately, that hasn’t been the case.
What I want to have happen is when an enemy is spawned have both players be able to see it and interact with it. (EX: do damage, take damage, etc.) What is happening right now is an enemy is spawned but only one player can see it and interact with it. The enemy will chase and interact with both players but only one player can see them. Its super confusing.
Here is the code that I am using on a object in the scene:
var spawnPoints : Transform[]; // Array of spawn points to be used.
var enemyPrefabs : GameObject[]; // Array of different Enemies that are used.
var amountEnemies = 20; // Total number of enemies to spawn.
var yieldTimeMin = 2; // Minimum amount of time before spawning enemies randomly.
var yieldTimeMax = 5; // Don't exceed this amount of time between spawning enemies randomly.
function Start(){
//networkView.RPC("Spawn", RPCMode.All);
Spawn();
}
function Spawn(){
if(Network.isServer && networkView.isMine){//I only want the "server" player to do the instantiation
for (i=0; i<amountEnemies; i++){ // How many enemies to instantiate total
yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax)); // How long to wait before another enemy is instantiated.
var obj : GameObject = enemyPrefabs[Random.Range(0, enemyPrefabs.length)]; // Randomize the different enemies to instantiate.
var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)]; // Randomize the spawnPoints to instantiate enemy at next.
Network.Instantiate(obj, pos.position, Quaternion.identity,0); //Spawn enemy for all players
}
}
}
Any help one this one would be greatly appreciated.
Oh! Also as a side note a network view is attached to the gameobject that has this script on it.