How to teleport a gameobject using tags instead of setting 1 game object each to respawn point?[SOLVED]

So I actually respawned the player but I have plans to setup a character selection so I want to use tags instead. I want each character that has a player tag on it to teleport to the spawn point. Im not sure about my code but I’ve been researching though, so I think answers from the experts will give me a boost.

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

public class Die : MonoBehaviour
{

    public Transform Destination;
    public GameObject Player;



    void OnTriggerEnter2D(Collider2D other){
             Player = (GameObject)GameObject.FindWithTag("Player");
             Player.transform.position = Destination.transform.position;
        }


}

I actually did it but Im not so sure about the tags cause I still need to set up my character in script. Sorry for my bad english.

Hi there @cheetahfrostyking

In your code you are ignoring the secret sauce of the ‘OnTriggerEnter2D’ function which is its parameter ‘other’. You could, for example, use that parameter to check if the thing colliding is the player:

private void OnTriggerEnter2D(Collider2D other)
{
    if (other.CompareTag("Player"))
        other.transform.position = Destination.position;
}

Is that what you were looking for?

Note that ‘Destination’ is already a transform so you can access its position directly with:

Destination.position

Wow! Thank u. I gave u a reward.