Greetings!
I have my a Prefab named MaleSprite and set it as a Player Prefab under the Spawn Info in Network Manager which MaleSprite has Network Identity with Local Player Authority, Network Transform, Network Animator checked parameters and PlayerController script, everything works fine.
Now I have my 2nd prefab named Weapon and set it under the Registered Spawnable Prefabs in Network Manager which Weapon has Network Identity with Local Player Authority, Network Transform and Network Animator and checked parameters.
Basically, on PlayerController Script, it first instantiates the Weapon prefab and set its parent on MaleSprite then when when MaleSprite moves, Weapon moves and transforms to all the players, which is Good. However, when a player presses Left Click, it will send the bool value True to Weapon.animator.setBool(“Attack”, attack) which is attached to the Weapon prefab. It is visible on the local player, however animation doesn’t appear for other players, which is Bad.
I have tried this methods:
-
NetworkServer.SpawnWithClientAuthority(weapon, connectionToClient);
Problem: It works for the Host only, like when I attack, it animates to all the clients, but maintain in the current transform position, and spawns another one in the default transform position also, when other local player attacks (not host) it doesn’t animate to all the clients. -
Instead of on Player Controller as weapon.animator.setBool(“Attack”, attack); Meaning sending the state directly to the attached animator component of the Weapon. I made it on Player Controller as weapon.attackState(attack); wherein on Weapon Script it receives the value as public void attackState(bool attack){ status = attack; } then on void Update(){ animator.setBool(“Attack”, status); } Meaning I’ve sent the bool value to another method inside Weapon Script to change the state on Animator attached on Weapon prefab. It animates as well on the local player, but it doesn’t animate to all the clients.
-
Setting Weapon as a Player Prefab under Spawn Info in Network Manager, it works perfectly, it animates to all the client, however it replaces the original Male Sprite and the same event will occur with Male Sprite when instantiated.
-
Adding [SyncVar] at the top of status variable inside the Weapon Script.
-
Making a method of
[Command]
void CmdAttack() {
attack = true;
} -
Unchecked Local Player Authority.
None of them worked. Any workarounds?