Ok. Here are the problems I can see in your code.
1) There is a logical problem with this bit in your GameOver class
void OnTriggerEnter(Collider other)
{
if(other.tag == "Ball" || other.tag == "Ball2")
SceneManager.LoadScene("GameOver");
}
You say that you want to go to GameOver scene when both balls have entered the trigger, but this code does not do that, this codes makes you go to GameOver when either of the balls enter the trigger, why? Because of the condition you’re using. Right now, your code says something like If I touched ball1 OR ball2 then change scene. But what you want is different, you want your code to say if I have touched ball1 AND ball2 then change scene. How to do this? well first, your code needs to remember that you have already touched the ball, an easy way to do it is with boolean flags. You would add a boolean flag for ball1 and ball2 then check that in your if statement. Like this:
public bool ball1Flag;
public bool ball2Flag;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Ball")
ball1Flag = true;
else if(other.tag == "Ball2")
ball2Flag = true;
if(ball1Flag && ball2Flag)
SceneManager.LoadScene("GameOver");
}
This will work, however, it is actually a bad approach to solve the problem because it is not flexible. And this takes us to the second issue.
2) What if you want to add more balls? Let’s say you want to have 20 balls now. Are you going to declare 20 boolean fields ball1Flag, ball2Flag, ball3Flag … up to ball20Flag? And create tags for each of them? Never, you should never think of that. Remember that programmers should hate repeating themselves when writing code, and writing public bool ballNFlag; 20 times is repetitive isn’t it? So, how to solve this? Consider having just one tag and one field but instead of a bool field let’s make it an integer field, a counter, and all balls will share the same tag (“Ball”).
public int ballCounter;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Ball")
ballCounter++; //Increments counter by 1
if(ballCounter >= 2)
SceneManager.LoadScene("GameOver");
}
This will work too and it is a much better solution because you can easily change the number of balls later, and now you don’t even need to have all those booleans to tell you which ball is which, you just care that 2 balls entered.
Hope this helps!
One final note. As a programmer I advice you to stay away from booleans as much as possible, the more booleans you use, the harder it will be to understand the code you write. I know you said you’re new to coding but it is very important that you learn about good coding practices when writing object oriented code.
Regards