increasing speed of a player based on score?
im making a 2d endless skiing game and want to increase the speed of the player based on the score of the tricks he performs (like in alto and ski safari). i write this script, which calculates the players scroe based on the tricks he perdorms and increases his speed aaccordingly. but theres some extremely annoying bug that preventing this from happening, please help me fix this: public class trickscore2 : MonoBehaviour { private float flips = 0; private float deltaRotation = 0; private float currentRotation = 0; private float WindupRotation = 0; public static Rigidbody2D rigbod; float divideByNum = 0.25f; public Text scores; private int trickscore; private int iflip; private int oldscore; private int incInScore; public float speed; [SerializeField] private PlayerController playerController; // Start is called before the first frame update void Start() { speed = playerController.speed; scores = GetComponent(); rigbod = GameObject.Find("player").GetComponent(); } // Update is called once per frame void Update() { // speed = GameObject.Find("player").GetComponent().speed; deltaRotation = currentRotation - rigbod.transform.eulerAngles.z; currentRotation = rigbod.transform.eulerAngles.z; if (deltaRotation >= 300) deltaRotation -= 360; if (deltaRotation <= -300) deltaRotation += 360; WindupRotation += (deltaRotation); flips = WindupRotation / 340; iflip = (int)flips; iflip = iflip -1; trickscore = iflip 10; scores.text = "score " + trickscore; incInScore = trickscore - oldscore; if (incInScore >= 10) { oldscore = trickscore; } Debug.Log(incInScore);
//speed += (Mathf.Round(incInScore)) / 100.0f;
if (incInScore > 0)
{
Trick();
}
void Trick()
{
if (incInScore > 1 && incInScore >= 11)
{
speed = speed + 10.15f;
}
if (incInScore > 10 && incInScore <= 20)
{
speed = speed + 0.25f;
}
if (incInScore > 20 && incInScore <= 50)
{
speed = speed + 0.50f;
}
if (incInScore > 50 && incInScore <= 100)
{
speed = speed + 0.75f;
}
if (incInScore > 100 && incInScore <= 200)
{
speed = speed + 1f;
}
if (incInScore > 200)
{
speed = speed + 2f;
}
}
}
}