Just by looking at your code and description it is hard to know exactly what behavior you are looking for, but first let's look at what your code is doing. Look at the comment I've added in the code below:
if(col.collider.name == "Brick2" && isBlue == true){
Instantiate(brickPieces2,transform.position,transform.rotation);
brickPieces2.Play();
Destroy(col.gameObject);
score += 10;
// HERE...comboBall will always be set to 2, so
// the following if statement is useless. Your
// score will always be multiplied by two.
comboBall = 2;
if(comboBall == 2){
score = comboBall*score;
}
guiScore.text= "Score: " + score;
print("collided with brick");
}
I think what you really want to do is cut comboBall = 2;
from the Brick2 collision case and paste to the Brick3 collision case. So, OnCollisionEnter function becomes:
function OnCollisionEnter(col : Collision){
if(col.collider.name == "Brick3"){
Instantiate(brickPieces,transform.position,transform.rotation);
brickPieces.Play();
particle3 = true;
Destroy(col.gameObject);
score += 10;
guiScore.text= "Score: " + score;
renderer.material.mainTexture = blue;
isBlue = true;
// MOVED COMBO CODE TO HERE
comboBall = 2;
}
if(col.collider.name == "Brick2" && isBlue == true){
Instantiate(brickPieces2,transform.position,transform.rotation);
brickPieces2.Play();
Destroy(col.gameObject);
score += 10;
if(comboBall == 2){
score = comboBall*score;
}
guiScore.text= "Score: " + score;
print("collided with brick");
}
if(col.collider.name == "paddle"){
comboBall = 0;
}
}
This way, the following behavior is implemented:
- Brick2 is hit - comboBall set to 2.
- IF next item hit is Brick3:
- comboBall is 2, so score will be multiplied by 2.
- ELSE IF next item hit is paddle:
- comboBall is set to 0.
- IF next item hit is Brick3:
- comboBall is 0, so score will not be multiplied.
- ELSE IF next item hit is Brick2:
- go back to top bullet point.
Make sense? From your description, this looks like the behavior you're looking for. Let me know if there are any questions.