void OnCollisionEnter2D(Collision2D col) { int random = Random.Range(0, 5); if (col.transform.tag == "ball" && random == 1) { Rigidbody2D ItemInstance; itemChance(1); if (brickZähler > 5) { ItemInstance = Instantiate(RbitemPrefab[i], new Vector2(transform.position.x, transform.position.y), Quaternion.identity) as Rigidbody2D; ItemInstance.AddForce(new Vector2(0, -150)); } } if (col.transform.tag == "ball2" && random == 1) { Rigidbody2D ItemInstance; itemChance(2); if (brickZähler > 5) { ItemInstance = Instantiate(RbitemPrefab[i], new Vector2(transform.position.x, transform.position.y), Quaternion.identity) as Rigidbody2D; ItemInstance.AddForce(new Vector2(0, 150)); } } if (col.transform.tag == "ball") { Paddle1Script.player1Score += BrickScore; Destroy(gameObject); brickZähler--; } if (col.transform.tag == "ball2") { Paddle2Script.player2Score += BrickScore; Destroy(gameObject); brickZähler--; } }
void OnCollisionEnter2D(Collision2D col) { blockHealth--; if (blockHealth == 0) { int random = Random.Range(0, 3); if (col.transform.tag == "ball" && random == 1) { Rigidbody2D ItemInstance; itemChance(1); if (BrickPhysikScript.brickZähler > 5) { ItemInstance = Instantiate(RbitemPrefab[i], new Vector2(transform.position.x, transform.position.y), Quaternion.identity) as Rigidbody2D; ItemInstance.AddForce(new Vector2(0, -150)); } } if (col.transform.tag == "ball2" && random == 1) { Rigidbody2D ItemInstance; itemChance(2); if (BrickPhysikScript.brickZähler > 5) { ItemInstance = Instantiate(RbitemPrefab[i], new Vector2(transform.position.x, transform.position.y), Quaternion.identity) as Rigidbody2D; ItemInstance.AddForce(new Vector2(0, 150)); } } if (col.transform.tag == "ball") { Paddle1Script.player1Score += 200; Destroy(gameObject); BrickPhysikScript.brickZähler--; } if (col.transform.tag == "ball2") { Paddle2Script.player2Score += 200; Destroy(gameObject); BrickPhysikScript.brickZähler--; } } if (blockHealth == 2) { float rot = Random.value; float grün = Random.value; float blau = Random.value; while (blau >= 0.9 || blau <= 0.1 || grün >= 0.9 || grün <= 0.1 || rot >= 0.9 || rot <= 0.1) { rot = Random.value; grün = Random.value; blau = Random.value; } //rend.sharedMaterial = texture[0]; //GetComponentSpriteRenderer.color = Color.white; Color newColor = new Color(rot, grün, blau, 1.0f); GetComponent <SpriteRenderer>().color = newColor; } if (blockHealth == 1) { GetComponent <SpriteRenderer>().color = Color.white; //rend.sharedMaterial = texture[1]; } }