Hi I’ve been building this little prototype of a game with the old Unet systems and in the game there are doors that are either traps or safe, and they are generated randomly, but I can’t seem to get them to sync across all clients and server. Each client has it’s own unique group. The 2 scripts that are handling it are attached. I am new to unet and I know it’s probably something small but so far google and other forums have not helped. thanks.
this is the Door.cs script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Door : NetworkBehaviour
{
[SyncVar]
public bool isTrap;
private void Update()
{
if (isTrap)
{
GetComponent<MeshRenderer>().material.color = Color.red;
gameObject.tag = "Deadly";
}
else
{
GetComponent<MeshRenderer>().material.color = Color.gray;
gameObject.tag = "Untagged";
}
}
private void OnTriggerEnter(Collider other)
{
gameObject.SetActive(false);
if (other.CompareTag("Player"))
{
if (isTrap)
{
FindObjectOfType<PlayerController>().CmdDie();
}
}
}
public void Reactivate()
{
gameObject.SetActive(true);
}
}
this is the WallManager.cs script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class WallManager : NetworkBehaviour
{
public List<Door> doors;
public void OnEnable()
{
if (isServer)
{
// Randomise traps
bool oneDoorSafe = false;
foreach (Door door in doors)
{
door.Reactivate();
if (doors.Count == 1)
{
door.isTrap = false;
oneDoorSafe = true;
}
else
{
if (Random.Range(0, 100) >= (100f / doors.Count))
{
door.isTrap = true;
}
else
{
door.isTrap = false;
oneDoorSafe = true;
}
}
}
if (!oneDoorSafe)
{
doors[Random.Range(0, doors.Count)].isTrap = false;
}
}
}
}