how to build a score multiplier?

Started by
1 comment, last by LorenzoGatti 3 years, 8 months ago

i am working on an endless skiing game and i want to build a score multiplier that can allow the player to make combos. The multiplier ive built does multiply the score, but never stops. So the socre keeps increasing infinitely. ive been stuck in this problem for a week so any help is highly appreciated.

 public class tricksScore : MonoBehaviour
 {
 
     private float flips = 0;
     private float deltaRotation = 0;
     private float currentRotation = 0;
     private float WindupRotation = 0;
     public static Rigidbody2D rigbod;
     public Text scores;
     private int trickscore;
     private int iflip;
     private int oldscore;
     private int incInScore;
     public float speed;
     private float counter;
     private int flipscore;
     private int rockDestroy;
     private bool grounded;
     private int multiplier = 1;
     private bool isScore5 = false;
     //private int timesScoreInc = 0;
     // Collision2D coll;
 
 
     // Start is called before the first frame update
     void Start()
     {
         speed = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().speed;
         scores = GameObject.Find("score").GetComponent<Text>();
         rigbod = GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>();
         grounded = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().grounded;
     }
 
     // Update is called once per frame
 
     void Update()
     {
         grounded = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().grounded;
         rigbod.velocity = new Vector2(speed, rigbod.velocity.y);
         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;
         flipscore = (iflip * 10) * multiplier;
 
         trickscore = flipscore + rockDestroy;
         scores.text = "score " + trickscore;
 
         incInScore = trickscore - oldscore;
 
         if (incInScore >= 5)
         {
             isScore5 = true;
         }
 
         if (incInScore >= 5)
         {
             oldscore = trickscore;
         }
 
         //speed += (Mathf.Round(incInScore)) / 100.0f;
 
         if (incInScore > 1 && incInScore <= 10)
         {
             speed = speed + 0.15f;
             counter += 3f;
         }
         if (incInScore > 10 && incInScore <= 20)
         {
             speed = speed + 0.25f;
             counter += 3f;
         }
         if (incInScore > 20 && incInScore <= 50)
         {
             speed = speed + 0.50f;
             counter += 3f;
         }
         if (incInScore > 50 && incInScore <= 100)
         {
             speed = speed + 0.75f;
             counter += 3f;
         }
         if (incInScore > 100 && incInScore <= 200)
         {
             speed = speed + 1f;
             counter += 3.5f;
         }
         if (incInScore > 200)
         {
             speed = speed + 2f;
             counter += 4f;
         }
 
         /* if ( grounded == false)
          {
             multiplier = timesScoreInc + 1;
          }*/
 
         if (isScore5 == true)
         {
             multiplier = multiplier + 1;
             isScore5 = false;
         }
 
         if (grounded == true)
         {
             multiplier = 1;
             isScore5 = false;
 
         }
         Debug.Log(multiplier);
 
         if (speed > 5.15f)
         {
             speed -= 0.05f * Time.deltaTime;
         }
         else if (speed == 5.15f)
         {
             speed = 5.15f;
         }
 
         counter -= 1.0f * Time.deltaTime;
 
         if (counter < 0)
         {
             counter = 0;
         }
 
         //  if (incInScore >= 5)
         //{
         incInScore = 0;
         // timesScoreInc = 0;
         //}     
 
 
         if (incInScore < 0)
         {
             incInScore = incInScore * -1;
         }
     }
     private void OnCollisionEnter2D(Collision2D coll)
     {
 
         if (counter > 0)
         {
             if (coll.collider.tag == "rock")
             {
                 Destroy(coll.gameObject);
                 speed = speed + 0.15f;
                 rockDestroy = (rockDestroy + 5) * multiplier;
                 counter = counter + 2f;
             }
 
         }
     }
 
 
 }
Advertisement

n00bi3 said:
if (grounded == true) { multiplier = 1; isScore5 = false; }

Do you mean that multiplier is never reset to 1 because grounded is never true? How do you update grounded?

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement