the ball goes to each side of the goals it continues to say player 2 wins no matter what side whether it is left or right. When I try to fixed the code it will say player 1 wins for both sides I know my code is wrong if it does that. I did SceneManager.LoadScene(2) and SceneManager.LoadScene(3) but it show the same scene over and over again. What I can do to have one side player 1 wins and the other side player 2 wins?
Where is this script attached? I believe it is attached to 2 different gameObjects? One per player?
I would declare a public int PlayerIndex;
, give it a value in the inspector ( 1
or 2
according to the gameObject the script is attached to), and then, in the OnCollisionEnter
add a condition to know whether you must load one scene or the other. Something like :
if( Score == 5 )
{
if( PlayerIndex == 1 )
SceneManager.LoadScene( 2 );
else if( PlayerIndex == 2 )
SceneManager.LoadScene( 3 );
}