OnTriggerEnter problems (C#)

Hey
i have a little problem wit ontriggerenter in c#.

I created a little game where you can move a player and there are some enemys moving around.
I want, if the player collides with an enemy, the player will be teleported to the startpoint.

The Players BoxCollider is Trigger.
The Enemy is a sphere.

The script for resetting the Players Position ist attached on the Enemy:

using UnityEngine;

public class EnemyScript : MonoBehaviour
{
    public Transform Player;

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.name == ("Player"))
        {
            Player.transform.position = new Vector3(-19f, 1.5f, -19f);
        }
    }
}

but it does not work :confused:

It would be very nice, if you could help me :slight_smile:

best regards from Germany

Trigger colliders only register with certain conditions. Take a look near the bottom of this page - Unity - Manual: Introduction to collision and look at the Collision Action Matrix table.

Exactly… and when you believe you have met those conditions, put a Debug.Log(“Yup”) at the start of the trigger function to prove it is ever being called, let alone if the name is correct, which is a separate struggle.

For the name struggle, remember that if you have a prefab named "Player" and you Instantiate it, the instance is gonna be called "Player (clone)"