# Unity FPS Offline Multiplayer (MultiLan) Player Animation

I am creating an FPS game in local multiplayer. One player creates the hot-spot game, and the other one connects through WiFi network and plays the game. And i am doing this using unity MultiLan Package available in Unity Assets Store.

when the player connect to the Game i play the player animation like walk , jump etc. But the problem is animation can play only which player who host the Game, not play to other player who join the Game in host network.

That is Player Script.

private MNetwork networkSrc;
public Btn_Jump jumpScript;

void Awake() {
if (GetComponent<NetworkView>().isMine) {
trans = transform;
contr = trans.GetComponent<CharacterController>();

if (jumpScript == null) {
jumpScript = GameObject.Find ("3 Jump").GetComponent<Btn_Jump> ();
}
}
}
}

void Start() {
if (GetComponent<NetworkView>().isMine) {

// If it's my player : search the networkManager component
networkSrc = GameObject.Find("MNetwork").GetComponent<MNetwork>();
PlayerAnimatorComponent = GameObject.Find ("Swat").GetComponent<Animator> ();

FPS_Events.ChangeCharacterMotor(motor);
}

}
void Update() {

if (!networkSrc.isPlayerExitGame) {

if (currentMotor == null)
FPS_Events.ChangeCharacterMotor (motor);
try {

currentMotor.Update ();
} catch {
}

if (jumpScript.Player_jump) {

}
RunAnimation ();
}

}
}

void RunAnimation(){
GetComponent<NetworkView> ().RPC ("SyncAnimation", RPCMode.All);
}

[RPC]
void SyncAnimation(){
PlayerAnimatorComponent.SetFloat ("Walk",2f,0.1f,Time.deltaTime);

}
}


In this Script there is "Btn_DpadScript" object of Virtual joystick Script name is "Btn_DPad" for Player Movement.

When player move then "Player_Run" Boolean variable is true and play the Walk animation of player in SyncAnimation() method.

But it is stuck to play animation in all player in same network.

Any one can know how to play animation in all network player using MultiLan Package then tell me. I can't found in Google Search about player Animation in network using MultiLan Package.

what should i do don't know any one can suggestion then i really appreciate thank you.

You should need to use NetworkAnimator for your animation sync on clients

The NetworkAnimator is used to synchronize animations across the network.

Grab this simple Tutorial.

• i used this as u say. but there is a no change in Game Same problem after using network animator – Darshan Soni Feb 8 '17 at 6:11

This line looks suspect:

PlayerAnimatorComponent = GameObject.Find ("Swat").GetComponent<Animator> ();


This says "Find some object in the scene named Swat. I don't particularly care which one."

So if you spawn multiple player avatars, each one called "Swat", this line is liable to return just the first one (ie. the host player's avatar) every time, and never apply animation state variables to the other avatars in the game. The same will happen if remote players' avatars get spawned with a modified name, like "Swat (clone)" which no longer matches the search string.

In general, you should avoid looking up GameObjects by name - especially when searching the whole scene. Assigning them via an inspector variable, or via the script that spawns them, will be much more robust under a variety of use cases.

Both answers already showed whats wrong. You also odnt use networkview.isMine with Unet but the implemented network behaviour (!isLocalPlayer) together with the network identiy object.

In order to be able to use this, you first have to import the libary:

use UnityEngine.Networking

Then, your script must inherit from this libary, which you can do by changing the MonoBehavour to NetworkBehaviour, lkke so:

public Class YourClass : NetworkBehaviour {

ShootingScript shoot;

void Start(){

if(isLocalPlayer){

shoot = GetComponent<ShootingScript>();
shoot.enabled(true);

}
}


}

Theres no real need to activate your anim per player, because unity offers the transform view & the animator view. Simply add those two components and the network identity component. Make also sure to check "isLocal" on the network identity component. This way, unity will knows who is the localplayer and who not. Check out the starting guide whenever you are wondering how to do certain things. You need to approach Network Stuff much different then Non Network things. GameObject.Find is something you wouldnt want to use in a network based environment.

Greetings!