private void OnCollisionEnter2D(Collision2D collision) { if (GameManager.StartGame) { if (collision.gameObject.tag == "Star") { ParticleBling.Play(); collision.gameObject.transform.position = new Vector3(objMathRNG.NextValueFloat(-9, 9), objMathRNG.NextValueFloat(-5, 5), 0); GameManager.Score += 1; } if (collision.gameObject.tag == "Obstaculo" && !GameManager.GameOver) { animator.SetBool("Death", true); GameManager.GameOver = true; ParticleBurst.Play(); renderer.enabled = false; setSpeed(0); } } }
public void Spawn() { if (TileGrid != null) { minValues = new Vector3(TileGrid.editorPreviewOrigin.x, TileGrid.editorPreviewOrigin.y, 0); maxValues = new Vector3(TileGrid.editorPreviewOrigin.x + TileGrid.editorPreviewSize.x, TileGrid.editorPreviewOrigin.y + TileGrid.editorPreviewSize.y, 0); } var min = new Vector2(minValues.x + OffSetUnits, minValues.y + OffSetUnits); var max = new Vector2(maxValues.x - OffSetUnits, maxValues.y - OffSetUnits); for (int i = 0; i < Quantity; i++) { Vector2 position = new Vector2(); switch (type) { case SpawnType.Border: position = objMathRNG.getRandomSpawnPoint(min, max); break; case SpawnType.InScene: position = new Vector2(objMathRNG.NextValueFloat(min.x, max.x), objMathRNG.NextValueFloat(min.y, max.y)); break; } lstObj.Add(Instantiate(obj, position, Quaternion.identity)); } }