Last active
October 19, 2015 08:38
-
-
Save kihira/02eb64e1fe2c4680355b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
/// <summary> | |
/// Attach this script to any object that modifies the score on its death | |
/// </summary> | |
public class Score : MonoBehaviour { | |
public int score = 100; | |
void OnDestroy() | |
{ | |
GameObject.Find("Score").GetComponent<ScoreManager>().AddScore(score); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
using UnityEngine.UI; | |
public class ScoreManager : MonoBehaviour { | |
private int currScore; | |
private List<int> scores; | |
void Start () { | |
scores = new List<int>(); | |
} | |
void Update () { | |
if (scores.Count <= 0) return; | |
scores[0] -= 2; | |
currScore += 2; | |
if (scores[0] <= 0) | |
{ | |
scores.RemoveAt(0); | |
} | |
// Update text display for the score | |
var textComponent = gameObject.GetComponent<Text>(); | |
textComponent.text = currScore.ToString().PadLeft(8, '0'); | |
} | |
public void AddScore(int score) | |
{ | |
scores.Add(score); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment