public static float CalculateAtackSpeed( ref Animation animation, string reload, string attack, int attackSpeed, bool debug = false ) { var reloadLength = AnimationUtils.GetAnimationLength(animation, reload); var attackLength = AnimationUtils.GetAnimationLength(animation, attack); if (debug) { Debug.Log( "as: " + attackSpeed + Environment.NewLine + "asF: " + (float)attackSpeed + Environment.NewLine + "cASf" + ((float)attackSpeed / 100) ); } float aS = ((float)attackSpeed / 100); float fullCurrentTime = reloadLength + attackLength; if (debug) { Debug.Log("fullCurrentTime: " + fullCurrentTime); } float coeficient = (float)Math.Pow(1f / aS, 2); if (debug) { Debug.Log("coeficient: " + coeficient + ", attackSpeed: " + aS); } float desiredTime = coeficient * aS; if (debug) { Debug.Log("desiredTime: " + desiredTime); } float newSpeed = fullCurrentTime / desiredTime; if (debug) { Debug.Log("newDeterminedAnimationSpeed: " + newSpeed); } animation[reload].speed = newSpeed; animation[attack].speed = newSpeed; return(newSpeed); }
public static int GetDefaultAttackSpeed( Animation animation, string reload, string attack ) { var reloadLength = AnimationUtils.GetAnimationLength(animation, reload); var attackLength = AnimationUtils.GetAnimationLength(animation, attack); float fullCurrentTime = reloadLength + attackLength; var defaultAttackSpeed = 1 / fullCurrentTime; return((int)(defaultAttackSpeed * 100)); }