how to make 2d portals in sense of loping the players in a box

i want to make a game where the players when they walk into the right or left wall they get teleported seamlessly to the wall on the oposit side. i have tried this tutorial (link text) but it wont work for me.


if one of the Players (small cubes) walks out of the map left or right they get teleported on the other side

You just have to set the transform position.x value. do something like

if(transform.position.x>500)

transform.position.x=0

You can put it in update or better call that after you move your player.

Only use a SpawnPoint and this code you can modify some things to make this more funcional in your case

public class Portal : MonoBehaviour
{
    public GameObject portal2D;
    public GameObject playerP;

    private void Awake()
    {
        playerP = GameObject.FindGameObjectWithTag("player");
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        StartCoroutine(transport(collision.gameObject.GetComponent<Transform>()));
    }


    IEnumerator transport(Transform collision)
    {
        yield return new WaitForSeconds(0.05f);
        collision.position = new Vector2(portal2D.transform.position.x, portal2D.transform.position.y);
    }
}

Always remember “The truth is out there”