Need help with making player wrap around the screen

I am having a hard time figuring out a way so the player will wrap around the screen and for it to be able to do it no matter what size the screen is. Here is what I have so far:

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour 
{
    private Transform myTransform;
	Vector3 playerPosition;
	Vector2 viewCoords;
    public int playerSpeed = 5;

	// Use this for initialization
	void Start () 
    {
        myTransform = transform;
		playerPosition = transform.position;
		viewCoords = camera.WorldToViewportPoint(playerPosition);

	    // Spawn point       x   y   z
        // Postion to be at -3, -3, -1

        myTransform.position = new Vector3(-3, -3, -1);

	}
	
	// Update is called once per frame
	void Update () 
    {
	    // Move the player left and right

        myTransform.Translate(Vector3.right * playerSpeed * Input.GetAxis("Horizontal") * Time.deltaTime);

		if (viewCoords.x < 0f || viewCoords.x > 1f) 
		{
			playerPosition = new Vector3(playerPosition.x * -1, playerPosition.y, playerPosition.z);
		}
	}
}

Unity is telling me I need a camera attached to the player so I did that and what it does is that the player doesn’t appear to move when testing which I know why that is. So my question is do I need to make a wraping script for the camera to allow the player to wrap around the screen when it goes off screen or is there a way to do it in the Player script I made. I appreciate any help you all can give me,

I don’t see you updating the value of viewCoords anywhere so it will always have the value you assigned it in Start(). You should be updating that each frame.

You should also do more than one check using the bounds of the player. If your player have a collider, you can use collider.bounds.extents to check all edges of the player. If you don’t do this, you will see some popping when the character wraps since they will always wrap when their center point leaves the screen.

I would solve this problem by wrapping the player around the scene, and then setting a camera up to conform to the size of the scene. Conceptually the camera should be observing things, and I don’t think it’s a good idea to use it to influence game logic like that. But experiment with different set-ups and see how they work.

I don’t know why you’d want a camera attached to the player unless you want a first- or third-person perspective (which would make screen wrapping impossible).