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

public class Dzialo : MonoBehaviour
{
    [SerializeField] private GameObject lufa;
    [Header("Opcje")]
    [Range(0.0f, 10.0f)]
    [SerializeField]
    private float vRuchu = 2.0f;
    [Range(10.0f, 50.0f)]
    [SerializeField]
    private float vObrotu = 10.0f;
    [SerializeField] 
    private float kat = 0.0f;


    void Ruch()
    {
        //obrt lewo, prawo
        if (Input.GetAxis("Horizontal")!=0)
            transform.Rotate(0, Input.GetAxis("Horizontal") * vObrotu * Time.deltaTime, 0);
        //jazda przd,ty
        if (Input.GetAxis("Vertical") != 0)
            transform.position +=Input.GetAxis("Vertical") * transform.forward * vRuchu * Time.deltaTime;
        //podnies lufe
        if (Input.GetKey(KeyCode.W))
            kat-=vObrotu * Time.deltaTime;
        //opu lufe
        if (Input.GetKey(KeyCode.S))
            kat+= vObrotu * Time.deltaTime;
        kat=Mathf.Clamp(kat, -60.0f, 30.0f);
        lufa.transform.localEulerAngles = new Vector3(kat,
                                            lufa.transform.localEulerAngles.y,
                                            lufa.transform.localEulerAngles.z);
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Ruch();
    }
    private void FixedUpdate()
    {
        //Ruch();
    }
}
