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

public class PlayerMove : MonoBehaviour
{
    LevelManager levelManager;
    public float speed = 10f;
    public float TurnSpeed = 200f;
    Rigidbody rigidbody;

    //input Movement/Animations
    float InputX;
    float InputY;
    public Animator anim;
    float Speed = 20;
    float turnspeed = 200;
    public Vector3 direction;

    // Input management
    bool isFireKeptDown = false;

    private void Start()
    {
        levelManager = GameObject.FindObjectOfType<LevelManager>();
        direction = Vector3.zero;
        rigidbody = GetComponent<Rigidbody>();
    }

    private void Update() {
        // The player can only move if she hasn't to recharge
        if (!levelManager.hasToRecharge && !levelManager.duringQTE && levelManager.canMove)
        {
            Move();
        }

    }


    public void Move() {

        //direction.x = Input.GetAxis("Horizontal");
        //direction.z = Input.GetAxis("Vertical");


        //rigidbody.AddForce(direction * speed, ForceMode.VelocityChange);
        //Debug.Log(rigidbody.velocity);
        // transform.LookAt(direction);
        //return;
        

        InputX = Input.GetAxis("Horizontal") * TurnSpeed;
        InputY = Input.GetAxis("Vertical") * Speed;

        InputX *= Time.deltaTime;
        InputY *= Time.deltaTime;

        
        transform.Translate(0, 0, InputY);
        transform.Rotate(0, InputX, 0);

        if (InputY != 0) {
            anim.SetBool("GoRun", true);
        }
        else {
            anim.SetBool("GoRun", false);
        }

        

       

    }

    //Animazione Reload
    public void ReloadAnim() {

        if (Input.GetMouseButtonDown(0)) {
            anim.SetTrigger("Reload");
        }

    }

    public void spaventata() {

        if (Input.GetMouseButtonDown(1)) {
            anim.SetTrigger("spaventata");
        }

    }

}
