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;
}
}