My game has a score. The score is represented by gameobjects. The score increases by 10 on a collision event. These events can not be stopped. I would like for the score to stop increasing on conditional "GameOver".
I am wondering how to stop the score from increasing since the triggering event can not be stopped. Making score = 0 is not good because I want to have the player's end score displayed. I need to somehow disconnect the score from the instantiations at the time of GameOver. Or I need to make the score integer stay the same at the time of GameOver. This is really a conceptual question and I'm not sure how to tackle this problem. Any ideas?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class ScoreHandler : MonoBehaviour {
public int score = 0;
public List<GameObject> destroyList = new List<GameObject>();
public static GameObject[] Score;
// Use this for initialization
void Start () {
score -= 80;
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "carA") {
score += 10;
}
if(col.gameObject.name == "carB")
{
score += 10;
}
if(col.gameObject.name == "carC")
{
score += 10;
}
if(col.gameObject.name == "carD")
{
score += 10;
}
if(col.gameObject.name == "carE")
{
score += 10;
}
if(col.gameObject.name == "carF")
{
score += 10;
}
if(col.gameObject.name == "carG")
{
score += 10;
}
if(col.gameObject.name == "carH")
{
score += 10;
}
foreach (var go in destroyList)
{
Destroy(go);
}
destroyList.Clear();
string scoreText = score.ToString ();
Score = new GameObject[scoreText.Length];
for (int i = 0; i < scoreText.Length; i++) {
Score[i] = (GameObject)Instantiate (Resources.Load (scoreText
[i].ToString ()));
Score[i].layer = 8;
Score[i].transform.localScale = new Vector3 (0.02F, 0.02F,
0.02F);
Score[i].transform.localPosition = new Vector3 (0.013F + i *
0.01F, 0.12F, 0.0F);
Score[i].transform.Rotate (0, 180, 0);
destroyList.Add (Score[i]);
}
}
}
*This code box has a scroll bar.