﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class moveSpaceshipScript : MonoBehaviour
{
    private Rigidbody2D rb2d;
    public float movementSpeed = 0.2f;

    private Vector2 movementInput;
 
    public void OnMove(InputAction.CallbackContext context)
    {
        // Read the Vector2 value (X is horizontal, Y is vertical)
        movementInput = context.ReadValue<Vector2>();
    }


    // Start is called before the first frame update
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        float moveH = movementInput.x;

        if (rb2d.transform.position.x > 8f) { moveH = -1f; }
        if (rb2d.transform.position.x < -8f) { moveH = 1f; }
        rb2d.transform.Translate(new Vector3(moveH * movementSpeed, 0, 0));
    }
}
