Setting function to run on all clients but only work on the player that called it
I'm making a 2D multiplayer game using Unity Networking.
I've read the documentation section about multiplayer and networking. I still cannot figure out how to solve the following problem:
I have this whole function that controls the animator of the player. I want this function to run on all clients when it is called by the player, but I only want it to run on that particular player.
Example: If player 2 presses the key "Z" I want it to appear on all the clients the animation for pressing key "Z" only on the player that called it, which would be player 2.
This is the function that I am using to control the animator:
void Animation() {
//walking
if (movementVector != Vector2.zero && !animator.GetCurrentAnimatorStateInfo(0).IsName("Roll")) {
animator.SetBool("isWalking", true);
if (movementVector.x == 1 && movementVector.y == 0)
GetComponent<SpriteRenderer>().flipX = true;
else
GetComponent<SpriteRenderer>().flipX = false;
animator.SetFloat("horizontal", movementVector.x);
animator.SetFloat("vertical", movementVector.y);
//rolling
if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Roll")) {
animator.SetBool("roll", Input.GetKeyDown(KeyCode.X));
}
}
else
animator.SetBool("isWalking", false);
//slash
if (Input.GetKeyDown(KeyCode.Z)) {
animator.Play("Slash", 0, 0);
}
}
PS: I have tried using the Network Animator component, but it doesn't work like a want it to because I am also using "Flip X" on the sprite renderer.
I hope my explanation made sense, I basically want all the players to have their own animations. The Network Animator component isn't working like I want it to.