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

public class PlayerMovement : MonoBehaviour {
    public int playerSpeed = 10;
    public int whichPlayer = 1;

    public Animator animator;

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		float valueHorizontal = Input.GetAxis ("Horizontal_P"+ whichPlayer);
        transform.position += new Vector3(valueHorizontal*Time.deltaTime*playerSpeed, 0f,0f);
        if (valueHorizontal > 0.1)
        {
            GetComponent<SpriteRenderer>().flipX = true;
        }
        else if (valueHorizontal < -0.1)
        {
            GetComponent<SpriteRenderer>().flipX = false;
        }
        float valueVertical = Input.GetAxis("Vertical_P"+ whichPlayer);
        transform.position += new Vector3(0f, valueVertical * Time.deltaTime * playerSpeed, 0f);
        transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.y+100);

        if (valueVertical > 0.1f || valueVertical < -0.1f || valueHorizontal > 0.1f || valueHorizontal < -0.1f)
        {
            animator.SetInteger("anim", 1);
        }
        else
        {
            animator.SetInteger("anim", 0);
        }

    }
}
