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

public class playerkontrol : MonoBehaviour
{
    AudioSource ses;
    Rigidbody fizik;
    float yatay;
    float dikey;
    Vector3 vec;
    public int hiz;
    public float minX;
    public float maxX;
    public float minZ;
    public float maxZ;
    public int egim;
    public float ateszamani = 0;
    public GameObject kursun;
    public Transform kursununCikisYeri;
    // Use this for initialization
    void Start()
    {
        fizik = GetComponent<Rigidbody>();
        ses = GetComponent<AudioSource>();
        hiz = 6;
        minX = -4;
        maxX = 3.83f;
        minZ = -1.83f;
        maxZ = 10;
        egim = -2;
        ateszamani = 0;
    }
    void Update()
    {
        if (Input.GetButton("Fire1") && Time.time > ateszamani)
        {
            ateszamani = Time.time + 0.3f;
            Instantiate(kursun, kursununCikisYeri.position,Quaternion.identity);

            ses.Play();
            
            Debug.Log("Ates Edildi");
        }
    }
    
    // Update is called once per frame
    void FixedUpdate()
    {
        yatay = Input.GetAxis("Horizontal");
        dikey = Input.GetAxis("Vertical");
        vec = new Vector3(yatay, 0, dikey);
        fizik.velocity = vec * hiz;
        fizik.position = new Vector3(Mathf.Clamp(fizik.position.x, minX, maxX), 0.0f, Mathf.Clamp(fizik.position.z, minZ, maxZ));
        fizik.rotation = Quaternion.Euler(0, 0, fizik.velocity.x * -egim);
    }
}
