Trigger Not Working

using UnityEngine;
using System.Collections;

public class EndLevel : MonoBehaviour {

    public Transform SpawnPoint;

    public int level;


    void OnTriggerEnter (Collider other){
        if (other.gameObject.tag == "Player") {

        gameObject.transform.position = new Vector3(SpawnPoint.position.x, SpawnPoint.position.y);
        level ++;
        }
    }
}

My trigger doesn’t get triggered with the OnTriggerEnter function. “Is Trigger” is checked on the box collider of the object, and the other is just a circle collider. Why isn’t this working?

does something involved in the collision have a rigidbody attached to it? without that the physics engine doesn’t know about it

Yes, the player does have a rigidbody2D component attached.

If this is 2d you need to use OnTriggerEnter2D

1 Like

If you are teleporting the player then the transform line needs to be other.gameObject.transform.position =…

& your vector3 for where you move it needs to have a z parameter

This solved my problem. Thank you!