I am making a game in which if you touch the flag you should go to the exit scene I even arranged it like <scene 1 then scene2 and then scene 3> but its not working if I touch the flag

I am making a game in which if you touch the flag you should go to the exit scene I even arranged it like

  1. “scene 1”
  2. “scene2”
  3. “scene 3”

but its not working if I touch the flag

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class IfTouched : MonoBehaviour
{
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.name == "Player")
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }
}

Ok so:
Flag GameObject:

  1. Drag/put your IfTouched script on the flag.
  2. Add BoxCollider (or any other collider you like) on the flag object.
  3. Click on Is Trigger (yes) (tick).

Player GameObject

  1. Player needs to have Rigidbody component on it.
  2. If is falling down change Gravity Scale to 0 (in the Rigidbody).
  3. Add BoxCollider (or any other collider you like) on the Player object.
  4. Make sure the Player object tag is set to Player

Now collision should work.
You can add print to see in Console if the collision works.

if (other.gameObject.name == “Player”)
{
print(“Collision works”);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}