- Home /
Change Scene When All balls Enter Collider
In my scene there are 3 balls, So i want to change/Load next scene when all those balls Enter the collider.
3 balls are in scene with the name and tag player1, player2, player3 This script is Working But only with one ball
public class SceneChange : MonoBehaviour {
void OnTriggerEnter(Collider other) {
if (other.CompareTag ("Player1")) //trigger event for Player1
{
Application.LoadLevel(2);
}
}
}
But when i try to add multiple player/ball it does not work.
if (other.CompareTag ("Player1") && other.CompareTag ("Player2") && other.CompareTag ("Player3"))
{
Application.LoadLevel(2);
}
Comment
Best Answer
Answer by Hellium · Mar 04, 2017 at 08:33 AM
public class SceneChange : MonoBehaviour
{
private bool player1Entered = false ;
private bool player2Entered = false ;
private bool player3Entered = false ;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag ("Player1")) player1Entered = true ;
else if (other.CompareTag ("Player2")) player2Entered = true ;
else if (other.CompareTag ("Player3")) player3Entered = true ;
if( player1Entered && player2Entered && player3Entered )
UnityEngine.SceneManagement.SceneManager.LoadScene (2);
}
}