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

public class MoveAndWrap : MonoBehaviour
{
    public float moveSpeed = 1f;

    public float maxX = 11f;
    public float minX = -11f;

    // Update is called once per frame
    void Update()
    {
        // get the object's current position, store it in a Vector3 called curPos
        Vector3 curPos = gameObject.transform.localPosition;

        float currentX = curPos.x;

        if (currentX < minX)
        {
            currentX = maxX;
        }

        if (currentX > maxX)
        {
            currentX = minX;
        }

        // set the current position + moveSpeed in a new Vector3, set the player's position to the new Vector3
        gameObject.transform.localPosition = new Vector3(currentX + (moveSpeed * Time.deltaTime), curPos.y, curPos.z);
    }
}