"teleport" player depend on screen width

I want my sides to be “connected” if the player exits from the right side of the screen he will get out of the left, and the opposite, same as in Doodle Jump

Tranform your player’s world position to screen position (Camera.main.WorldToScreenPoint), then check his X-coordinate in screen space. If it’s less than 0 he’s to the left of your screen, if it’s more then Screen.width hes at off screen at the right, so you need to teleport him.

Determining where to teleport him to is essentially the same but in reverse: determine the point on the screen you want to have him appear, then transform that to world coordinates (Camera.main.ScreenToWorldPoint), then teleport your player to that position.

try to do it in 2 javascripts.the first script:

var leftSide : Transform;

var rightSideScript : NameOfTheScript;

var character : GameObject;

function OnTriggerEnter()

{

        if(character.transform.position == leftSide.position)

        {

            character.transform.position = rightSideScript.rightSide.position;
  
            Debug.Log("Side Changed");

        }

}

the second script:

var rightSide : Transform;

var leftSideScript : NameOfTheScript;

function OnTriggerEnter()

{

        if(leftSideScript.character.transform.position == rightSide.position)

        {

              leftSideScript.character.transform.position = leftSideScript.leftSide.position;

              Debug.Log("Side Changed")

        }

}

now you need to insert the right side script in a gameobject on the right side of the script and the same thing for the left side. to the gameobjects add a box collider and set it as a trigger. on the left side script add the character gameobject and the right side gameobject and add himself. to the right add the left side gameobject and himself. now it showld work.

I am using this script and how can i change it so if the player goes to the right he teleport to the left. My idea was copy and past the TeleportRight() and rename it to TeleportLeft() and make the transform.position = targetWorldPos; to transform.position = - targetWorldPos that works but the players y axis isn’t working so if my player has a y value of y-3 he teleports to y3 how to fix that?