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

public class LocationManager : MonoBehaviour
{
    [SerializeField]
    private Transform currentLocation;
    [SerializeField]
    private float moveSpeed = 7f;
    [SerializeField]
    private float leftLimit = -3f;
    [SerializeField]
    private float rightLimit = 3f;

    public bool canMove = true;


    void Update()
    {
        if (canMove)
        {
            float input = Input.GetAxis("Horizontal");

            Vector3 newPosition = currentLocation.transform.position - new Vector3(input * moveSpeed * Time.deltaTime, 0, 0);

            newPosition.x = Mathf.Clamp(newPosition.x, leftLimit, rightLimit);

            currentLocation.transform.position = newPosition;
        }

    }


    public void ChangeLocation(Transform newLocation)
    {
        currentLocation.gameObject.SetActive(false);
        newLocation.gameObject.SetActive(true);
        currentLocation = newLocation;
    }
}
