So i have a spawn script as follows so this script successfully spawns the enemies the client and server sees them and they work just fine but i am trying to make it so when the enemy spawns several variables will be selected at random which they do
but the only problem is that for the server these variables are completely visible
the client on the other hand just sees them as the original prefab
how can i make it so the client will also see the variables changed on the enemy when it spawns?
using UnityEngine.Networking;
using UnityEngine;
public class Enemyspawn : NetworkBehaviour
{
public GameObject objectToSpawn;
public float timeToWaitBetweenSpawns = 20f;
public float timer = 0;
public bool canspawn;
[SyncVar]
public float weight;
[SyncVar]
public Vector3 npcsize;
[SyncVar]
public float size;
public GameObject enemy;
GameObject[] players;
public GameObject spawnbutton;
bool gameStarted = false;
private void Start()
{
if(!isServer)
{
Destroy(spawnbutton);
Destroy(gameObject);
}
}
[ClientRpc]
void Rpc_playersize()
{
enemy.GetComponent<Charactersize>().weight = weight;
size = weight / 100f / 1.3f;
enemy.transform.localScale = new Vector3(size, size, size);
}
public void SpawnEnemy()
{
weight = Random.Range(60, 400);
enemy.GetComponent<Charactersize>().weight = weight;
size = weight / 100f / 1.3f;
npcsize = new Vector3(size, size, size);
enemy.transform.localScale = npcsize;
enemy = (GameObject)Instantiate(objectToSpawn, transform.position, transform.rotation);
NetworkServer.Spawn(enemy);
}
}