Setting Multiple Player Animation States with Unity Animator

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
User avatar
IdleChimp
Posts: 10
Joined: 19 Dec 2022, 01:00

Setting Multiple Player Animation States with Unity Animator

Post by IdleChimp »

So, setting the player state with on logged in player works well. But when I loop through the players in the scene and try to set there animation state, everything goes to hell in a handbasket.



Looping through my network players:

Code: Select all


	
	int id = data.GetInt("id");
	int i = 0;
	int total = Players.Count;

	for (i = 0; i < total; i++)
        {



            NetworkPlayer player = Players[i];

            if (player.Id == id)
            {

                string animation = data.GetUtfString("animation");
                player.SetPlayerAnimation(animation);


            }//end if



	 }//end for



Code on my network player:

Code: Select all

public void SetPlayerAnimation(string animation)
    {

        if (_animator == null) return;


        string trimmed = animation.Trim();


        //ANIMATION
        switch (trimmed)
        {


            case AnimationState.IDLE:
                _animator.SetInteger("AnimationState", 0);
                break;


            case AnimationState.WALK:
                _animator.SetInteger("AnimationState", 1);
                break;


            case AnimationState.WALK_BACK:
                _animator.SetInteger("AnimationState", 2);
                break;


            case AnimationState.STRAFE_LEFT:
                _animator.SetInteger("AnimationState", 3);
                break;


            case AnimationState.STRAFE_RIGHT:
                _animator.SetInteger("AnimationState", 4);
                break;


            default:
                _animator.SetInteger("AnimationState", 0);
                break;


        }//end switch


    }//end
It's like it only affects one player at a time. Making the animation states only set for one player? It's weird.

Any help appreciated!

Thanks,
IdleCHimp
Post Reply