//using NUnit.Framework; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Sphere : MonoBehaviour { public GameObject GameOverPanel; public GameObject GameOverOptions; public GameObject SpherePrefab; public Color[] ListOfColors; List listLevel1 = new List(); List listLevel2 = new List(); List center2 = new List(); List listLevel3 = new List(); List center3 = new List(); List listLevel4 = new List(); List center4 = new List(); List center5 = new List(); List> listOfLists = new List>(); MeshRenderer m; Rigidbody rb; int num; bool end = false; void Start() { StartSetter(); } private void StartSetter() { end = false; GameOverPanel.SetActive(false); GameOverOptions.SetActive(false); listOfLists.Add(listLevel1); listOfLists.Add(center2); listOfLists.Add(center3); listOfLists.Add(center4); listOfLists.Add(center5); num = Random.Range(0, ListOfColors.Length); m = GetComponent(); m.material.color = ListOfColors[num]; rb = GetComponent(); } void Update() { if (end) { if (Input.GetKeyDown(KeyCode.Escape)) { print("Escaped"); Application.Quit(); } if (Input.GetKeyDown(KeyCode.Tab)) { print("Reloaded"); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } return; } float xNew = transform.position.x; float zNew = transform.position.z; if (Input.GetKeyDown(KeyCode.RightArrow)) { xNew++; if (xNew > 3.5f) { xNew = 3.5f; } } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { xNew--; if (xNew < -3.5f) { xNew = -3.5f; } } if (Input.GetKeyDown(KeyCode.UpArrow)) { zNew++; if (zNew > 3.5f) { zNew = 3.5f; } } else if (Input.GetKeyDown(KeyCode.DownArrow)) { zNew--; if (zNew < -3.5f) { zNew = -3.5f; } } transform.position = new Vector3(xNew, transform.position.y, zNew); } private void OnCollisionEnter(Collision coll) { Vector3 positionOld = transform.position; Color mOld = ListOfColors[num]; if (positionOld.y < 4) { transform.position = new Vector3(-0.5f, 10, -0.5f); num = Random.Range(0, ListOfColors.Length); m.material.color = ListOfColors[num]; rb.drag = rb.drag * 0.98f; GameObject gameObjectReference = Instantiate(SpherePrefab, positionOld, Quaternion.identity) as GameObject; gameObjectReference.GetComponent().material.color = mOld; if (positionOld.y < 1) { listLevel1.Add(gameObjectReference); } else if (positionOld.y < 2) { if (positionOld.x == 0.5f | positionOld.x == -0.5f) { center2.Add(gameObjectReference); } else { listLevel2.Add(gameObjectReference); } } else if (positionOld.y < 2.5) { if (positionOld.x == 0.5f | positionOld.x == -0.5f) { center3.Add(gameObjectReference); } else { listLevel3.Add(gameObjectReference); } } else if (positionOld.y < 3) { if (positionOld.x == 0.5f | positionOld.x == -0.5f) { center4.Add(gameObjectReference); } else { listLevel4.Add(gameObjectReference); } } else if (positionOld.y < 4) { if (positionOld.x == 0.5f | positionOld.x == -0.5f) { center5.Add(gameObjectReference); } } CheckLines(); } else { end = true; StartCoroutine("GameOver"); } } private IEnumerator GameOver() { yield return new WaitForSeconds(1f); GameOverPanel.SetActive(true); StartCoroutine("GameOverOpts"); } private IEnumerator GameOverOpts() { yield return new WaitForSeconds(1f); GameOverOptions.SetActive(true); } void CheckLines() { if (listLevel1.Count == 4) { for (int k = listLevel1.Count - 1; k >= 0; k--) { Destroy(listLevel1[k]); listLevel1.RemoveAt(k); } for (int i = 1; i < listOfLists.Count; i++) { listOfLists[i - 1].AddRange(listOfLists[i]); listOfLists[i].Clear(); } } //int count2 = 0; //for (int k = 0; k < listLevel2.Count; k++) //{ // count2++; //} //if (count2 == 16) //{ // for (int k = listLevel2.Count - 1; k >= 0; k--) // { // Destroy(listLevel2[k]); // listLevel2.RemoveAt(k); // } //} //int count3 = 0; //for (int k = 0; k < listLevel3.Count; k++) //{ // count3++; //} //if (count3 == 36) //{ // for (int k = listLevel3.Count - 1; k >= 0; k--) // { // Destroy(listLevel3[k]); // listLevel3.RemoveAt(k); // } //} //int count4 = 0; //for (int k = 0; k < listLevel4.Count; k++) //{ // count4++; //} //if (count4 == 64) //{ // for (int k = listLevel4.Count - 1; k >= 0; k--) // { // Destroy(listLevel4[k]); // listLevel4.RemoveAt(k); // } //} } }