Hi I have used the older version of Unity, and just getting back into it, but I seem to be having an issue with a simple Level Loading Script. I am using a Player that is tagged “Player” and when he collides with an object, the next scene loads. This is what I have for code, and I made sure the Scenes are in my build, as well as IsTrigger is selected on both objects just in case.
public class NextLevel : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == “Player”)
{
SceneManager.LoadScene(2);
}
}
}
If you have IsTrigger selected, then OnCollisionEnter will never work. Instead, you’d need OnTriggerEnter.
Also, look here, at the very bottom: Unity - Manual: Introduction to collision
For your trigger to work, one of the two objects will probably need a Rigidbody on it, even if the Rigidbody is kinematic. You’ll note on that page that “static” triggers don’t trigger each other, and “static” colliders don’t interact with static triggers. So, try putting a rigidbody on one of the objects.
Also, a minor thing: For performance reasons, it’s better to use gameObject.CompareTag, rather than doing a == comparison to a string. It reduced garbage.