Author Topic: I tryed to make animator sync script,but it has isues  (Read 3177 times)

defender1213

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
I tryed to make animator sync script,but it has isues
« on: January 29, 2018, 01:50:43 PM »
I tryed to make animator sync script,but it has isues and dont works correct at all,please help me to fix this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TNet;
public class TN_Animator : TNBehaviour{
    Animator anim;
    [SerializeField] int updates=10;
    float uptouse=0;
    float[] data;
    int[] param;
    string[] _name;
    void Awake()
    {
        anim = GetComponent<Animator>();
        param = new int[anim.parameterCount];
        _name = new string[anim.parameterCount];
        for(int i = 0; i != anim.parameterCount; i++)
        {
            if (anim.parameters.type == AnimatorControllerParameterType.Bool) param = 0;
            else if (anim.parameters.type == AnimatorControllerParameterType.Float) param = 1;
            else if (anim.parameters.type == AnimatorControllerParameterType.Int) param = 2;
            else if (anim.parameters.type == AnimatorControllerParameterType.Trigger) param = 3;
            _name =  anim.parameters.name;
        }
        data = new float[anim.parameterCount];
        uptouse = updates;
    }
    void FixedUpdate()
    {
        if (tno.isMine)
        {
            uptouse -= Time.fixedDeltaTime;
            if (uptouse <= 0)
            {
                for (int i = 0; i != anim.parameterCount; i++)
                {
                    if (Equals(param, 0)) if (Equals(anim.GetBool(_name), true)) data = 0; else data = 1;
                    else if (Equals(param, 1)) data = anim.GetFloat(_name);
                    else if (Equals(param, 2)) data = anim.GetInteger(_name);
                    else if (Equals(param, 3)) if (Equals(anim.GetBool(_name), true)) data = 0; else data = 1;
                }
                tno.SendQuickly("UpPram", Target.Others, data);
                Debug.Log(data);
                uptouse = updates;
            }           

        }
    }
    [RFC]void UpPram(float[] data)
    {
        for(int i=0;i!=data.Length;i++)
        {
            if (Equals(param, 0)) if (Equals(data,0 ))anim.SetBool(_name,true); else anim.SetBool(_name, false);
            else if (Equals(param, 1)) anim.SetFloat(_name, data);
            else if (Equals(param, 2)) anim.SetInteger(_name, (int)data);
            else if(Equals(param, 3)) if (Equals(data, 0)) anim.SetTrigger(_name);
        }
        this.data = data;
    }
   
}

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: I tryed to make animator sync script,but it has isues
« Reply #1 on: February 10, 2018, 09:08:42 AM »
The usual practice is to sync the action not the reaction. Animation occurs as a reaction to something, for example: player presses left-click to attack with a sword, the swing animation then plays. You'd want to send the "player has pressed left-click" part over the network and not the "sword is swinging" part.

I think this applies well in all cases, even with something like a ragdoll.