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

[System.Serializable]
public class Boundary
{
    public float xMin, xMax, yMin, yMax; //Screen Boundary dimentions
}

public class Player_script : MonoBehaviour
{
    //Public Var
    public Boundary boundary;       //make an Object from Class Boundary
    public float speed;
    public GameObject playerShout;

    //Private Var
    private Rigidbody2D rb2D;
    private float moveHorizontal, moveVertical;

    // Use this for initialization
    void Start()
    {
        rb2D = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            playerShout.SetActive(false);
            playerShout.SetActive(true);
        }
    }

    void FixedUpdate()
    {
        Move();
    }

    private void Move()
    {
        moveHorizontal = Input.GetAxis("Horizontal");
        moveVertical = Input.GetAxis("Vertical");
        Vector2 movement = new Vector2(moveHorizontal, moveVertical);
        rb2D.velocity = movement * speed;

        //Lock the position in the screen by putting a boundaries
        rb2D.position = new Vector2
            (
                Mathf.Clamp(rb2D.position.x, boundary.xMin, boundary.xMax),  //X
                Mathf.Clamp(rb2D.position.y, boundary.yMin, boundary.yMax)   //Y
            );
    }
}
