I am trying to make a double points powerup and am really close to figuring it out! I created a multiplier in my scoremanager and set it equal to one. When the player collides with the X2 object the multiplier is incremented by 1 (multiplier++). My code works briefly, but then the score starts getting ridiculously high. I decremented the multiplier (multiplier–) after the powerup duration is finished, but that does not seem to work. I would appreciate any help.
Here my code:
Code1:
using UnityEngine;
using System.Collections;
public class Multiplier : MonoBehaviour {
public GameObject particle;
public AudioClip powerUpSound;
public float time;
bool Active=false;
void Update(){
if (Active==false) {
StartCoroutine (DestroyGameObject ());
}
}
IEnumerator ScoreMultiplier(){
Active = true;
ScoreManager .multiplier ++;
yield return new WaitForSeconds (time);
ScoreManager.multiplier--;
Destroy (gameObject);
}
IEnumerator DestroyGameObject(){
yield return new WaitForSeconds (3);
gameObject.GetComponent <SpriteRenderer > ().enabled = false;
yield return new WaitForSeconds (17);
Destroy (gameObject);
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Player") {
Active = true;
gameObject.GetComponent <SpriteRenderer > ().enabled = false;
StartCoroutine (ScoreMultiplier ());
}
}
}
Code 2 (Attached to player):
using UnityEngine;
using System.Collections;
using UnityEngine .Audio ;
using UnityEngine .SceneManagement ;
public class Player : MonoBehaviour {
private int Base_Reward1=100;
private int Base_Reward2=200;
private int Base_Reward3=300;
public void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Running Player1") {
ScoreManager.scoreCount += Base_Reward1*=ScoreManager .multiplier;
Destroy (other.gameObject);
}
}
}