Created
June 6, 2018 11:49
-
-
Save walkies/2759c2540306c97ed11309c1f14007be to your computer and use it in GitHub Desktop.
Countdown timer updated
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine.UI; | |
using UnityEngine; | |
public class Countdown : MonoBehaviour | |
{ | |
public GameObject ball; | |
public GameObject Canvas; | |
public GameObject Panel; | |
public GameObject SecretPanel; | |
public GameObject ballentry; | |
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 >= 1000) | |
{ | |
Time.timeScale = 0; | |
SecretPanel = Canvas.transform.Find("SecretEndPanel").gameObject; | |
SecretPanel.SetActive(true); | |
} | |
if (currentScore == 20) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 40) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 60) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 80) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 100) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 140) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 180) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 220) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 260) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 300) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 320) | |
{ | |
spawnball(); | |
} | |
else if (currentScore == 340) | |
{ | |
spawnball(); | |
} | |
} | |
public IEnumerator StartCountdown(int countdownValue = 50) | |
{ | |
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); | |
} | |
} | |
void spawnball() | |
{ | |
ballentry.GetComponent<AudioSource>().Play(); | |
Instantiate(ball, new Vector3(0, 3f, 2), Quaternion.Euler(0, 180, 0)); | |
currentScore++; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment