using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Block : MonoBehaviour {
public GameObject ScorePU;
public GameObject SmallBallPU;
public GameObject BigBallPU;
public GameObject FastBallPU;
public GameObject SlowBallPU;
public GameObject SplitBallPU;
private GameObject ReplacePU;
public GameObject BombExplosion;
public GameObject BlockBomb;
public GameObject BlockPowerUp;
void OnCollisionEnter(Collision col){
// There is my other scripts…
if (type==Type.Bomb){
Collider[] DestroyedObjects = Physics.OverlapSphere(this.transform.position,1.5f);
Instantiate(BombExplosion, this.transform.position, BombExplosion.transform.rotation);
foreach(Collider UnRequiredBlocks in DestroyedObjects){
if(UnRequiredBlocks.tag == "UnRequiredBlocks"){
Destroy(UnRequiredBlocks.gameObject);}
if(UnRequiredBlocks.gameObject == BlockBomb){
Instantiate(BombExplosion, BlockBomb.transform.position, BombExplosion.transform.rotation);}
if(UnRequiredBlocks.gameObject == BlockPowerUp){
int RandomReplace = Random.Range(0,6);
if (RandomReplace == 0){ReplacePU = (GameObject)Instantiate(ScorePU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 1){ReplacePU = (GameObject)Instantiate(SmallBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 2){ReplacePU = (GameObject)Instantiate(BigBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 3){ReplacePU = (GameObject)Instantiate(FastBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 4){ReplacePU = (GameObject)Instantiate(SlowBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 5){ReplacePU = (GameObject)Instantiate(SplitBallPU, this.transform.position, this.transform.rotation);}}}}}
GameObject’s with ending PU = powerup, gives a powerup to character
GameObject ReplacePU = randomly creates one powerup
GameObject BlockBomb = a cube that explodes on character’s touch
GameObject BlockPowerUp = a cube that creates a ReplacePU
if(type == Type.Bomb) = Type is an public enum
GameObject BombExplosion = an explode animation, used for BlockBomb
Problem Starts from:
Collider[] DestroyedObjects = Physics.OverlapSphere(this.transform.position,1.5f);
Instantiate(BombExplosion, this.transform.position, BombExplosion.transform.rotation);
foreach(Collider UnRequiredBlocks in DestroyedObjects){
if(UnRequiredBlocks.gameObject == BlockBomb){
Instantiate(BombExplosion, BlockBomb.transform.position, BombExplosion.transform.rotation);}
if(UnRequiredBlocks.gameObject == BlockPowerUp){
int RandomReplace = Random.Range(0,6);
if (RandomReplace == 0){ReplacePU = (GameObject)Instantiate(ScorePU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 1){ReplacePU = (GameObject)Instantiate(SmallBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 2){ReplacePU = (GameObject)Instantiate(BigBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 3){ReplacePU = (GameObject)Instantiate(FastBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 4){ReplacePU = (GameObject)Instantiate(SlowBallPU, this.transform.position, this.transform.rotation);}
if (RandomReplace == 5){ReplacePU = (GameObject)Instantiate(SplitBallPU, this.transform.position, this.transform.rotation);}}}}}
1. At first if if(UnRequiredBlocks.gameObject == BlockBomb)
It creates 2 explosions at same position, 1st: from starting of foreach , 2nd: from this if.
But I need it to create 2 explosions at different positions, 1st: is correct position, 2nd: at position of BlockBomb.
2. At second if if(UnRequiredBlocks.gameObject == BlockPowerUp)
It Doesn’t create a random PowerUp.
But I need it to create a random PowerUp. I get confused because really SAME script works in if(type==Type.PowerUp) (I have more cubes that make functions, Type.PowerUp creates a powerup) but I need to make in Type.Bomb another PowerUp if it’s in range of an PowerUp cube… (If Bomb is exploded and near is an PowerUp cube, make same thing as PowerUp cube does [create a PowerUP {ReplacePU}])