Skip to content

Instantly share code, notes, and snippets.

@walkies
Created June 5, 2018 05:08
Show Gist options
  • Save walkies/42705107c574530f6cc56ae64c63e5c7 to your computer and use it in GitHub Desktop.
Save walkies/42705107c574530f6cc56ae64c63e5c7 to your computer and use it in GitHub Desktop.
Time and Score script
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Countdown : MonoBehaviour
{
public GameObject Canvas;
public GameObject Panel;
public GameObject SecretPanel;
public int currentTime;
public int currentScore;
public Text Count;
public Text Score;
public Text SecretScore;
void Start()
{
StartCoroutine(StartCountdown());
}
void Update()
{
Count.text = "" + currentTime.ToString();
Score.text = "" + currentScore.ToString();
SecretScore.text = "" + currentScore.ToString();
if (currentScore >= 350)
{
Time.timeScale = 0;
SecretPanel = Canvas.transform.Find("SecretEndPanel").gameObject;
SecretPanel.SetActive(true);
}
}
public IEnumerator StartCountdown(int countdownValue = 60)
{
currentTime = countdownValue;
while (currentTime > 0)
{
yield return new WaitForSeconds(1.0f);
currentTime--;
}
if (currentTime <= 0)
{
Time.timeScale = 0;
Panel = Canvas.transform.Find("EndPanel").gameObject;
Panel.SetActive(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment