Hello! I'm trying to implement an enemy in my game that moves only if no player is looking at it. As usual, if only one player played the game, everything worked fine, but implementing the multiplayer part has some bugs.
What I want: An enemy is instantiated in the scene, it roams, it finds the closest player and goes to it. If the enemy is visible in any of the player's cameras, it stops. If it has stopped for more than 10 seconds it dissapears and appears again after some time.
With what I have right now the only problems are that the clients can't stop the enemy if they are looking at it and sometimes, if the host is looking at the enemy for 10 seconds, the enemy dissapears for the host but not for the client(only sometimes this happens).
I want to use a bool for this (isRaycasted) and right now I'm using CMD and RPC's to sync the state. I also tried hook on the bool but still the same outcome like now. If the host is looking at the enemy, the bool is synced over everyone, but if the client is looking at the enemy, the bool is updated only locally and not for everyone else. I've left the important parts of the script down below if anyone has any idea. Thank you!
EDIT: Forgot to say that this with the cmd in the update was added only to test. I also added a coroutine that runs every second for this script to not overload the network with CMD's but still the same outcome.
