public void OnCollisionEnter2D(Collision2D collision) { GlobalGameState state = GameObject.Find("GlobalState").GetComponent <GlobalGameState>(); if (collision.gameObject.name.Equals("wave(Clone)")) { wave w = collision.gameObject.GetComponent <wave>(); if (state.colorId != w.waveID) { GameObject.Find("Miss").GetComponent <AudioSource>().Play(); state.hits++; if (state.hits == 1) { GameObject.Find("lose4").GetComponent <RectTransform>().localScale = new Vector3(0.10463f, 0.10463f, 0.10463f); } else if (state.hits == 2) { GameObject.Find("lose3").GetComponent <RectTransform>().localScale = new Vector3(0.10463f, 0.10463f, 0.10463f); } else if (state.hits == 3) { GameObject.Find("lose2").GetComponent <RectTransform>().localScale = new Vector3(0.10463f, 0.10463f, 0.10463f); } else if (state.hits == 4) { GameObject.Find("lose1").GetComponent <RectTransform>().localScale = new Vector3(0.10463f, 0.10463f, 0.10463f); } } else { state.score += 100 + (int)((10 * state.getSpeed()) / state.getSpawnTime()); } Destroy(collision.gameObject); if (state.hits == 4) { state.gameOver = true; GameObject.Find("Sounds").GetComponent <AudioSource>().Pause(); GameObject.Find("Boo").GetComponent <AudioSource>().Play(); Invoke("gameOver", 0.1f); } } }
void spawn() { int rand = (int)Random.Range(0, 6); GlobalGameState state = GameObject.Find("GlobalState").GetComponent <GlobalGameState>(); cloneLeft = null; cloneRight = null; switch (rand) { case 0: //purple cloneRight = Instantiate(toClone, spawnRight, Quaternion.identity) as GameObject; //cloneLeft.GetComponent<SpriteRenderer>().color = purple; cloneRight.GetComponent <SpriteRenderer>().color = purple; break; case 1: //yellow cloneLeft = Instantiate(toClone, spawnLeft, Quaternion.identity) as GameObject; cloneLeft.GetComponent <SpriteRenderer>().color = yellow; //cloneRight.GetComponent<SpriteRenderer>().color = yellow; break; case 2: //red cloneLeft = Instantiate(toClone, spawnLeft, Quaternion.identity) as GameObject; cloneLeft.GetComponent <SpriteRenderer>().color = red; //cloneRight.GetComponent<SpriteRenderer>().color = red; break; case 3: //blue cloneLeft = Instantiate(toClone, spawnLeft, Quaternion.identity) as GameObject; cloneLeft.GetComponent <SpriteRenderer>().color = blue; //cloneRight.GetComponent<SpriteRenderer>().color = blue; break; case 4: //green cloneRight = Instantiate(toClone, spawnRight, Quaternion.identity) as GameObject; //cloneLeft.GetComponent<SpriteRenderer>().color = green; cloneRight.GetComponent <SpriteRenderer>().color = green; break; case 5: //orange cloneRight = Instantiate(toClone, spawnRight, Quaternion.identity) as GameObject; //cloneLeft.GetComponent<SpriteRenderer>().color = orange; cloneRight.GetComponent <SpriteRenderer>().color = orange; break; } if (cloneLeft != null) { cloneLeft.AddComponent <waveMove>(); cloneLeft.GetComponent <waveMove>().right = false; cloneLeft.GetComponent <waveMove>().speed = state.getSpeed(); cloneLeft.transform.Rotate(0, 180, 0); cloneLeft.GetComponent <wave>().waveID = rand; } if (cloneRight != null) { cloneRight.AddComponent <waveMove>(); cloneRight.GetComponent <waveMove>().right = true; cloneRight.GetComponent <waveMove>().speed = state.getSpeed(); cloneRight.GetComponent <wave>().waveID = rand; } }