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

public class Strzal : MonoBehaviour
{
    [SerializeField] private GameObject prefabPocisk;
    [SerializeField] private GameObject praefabDymWystrzalu;
    [Header("Opcje")]
    [Range(10.0f,50.0f)]
    [SerializeField] private float v=10.0f;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyUp(KeyCode.Space)) 
        { 
            GameObject p=Instantiate(prefabPocisk,transform.position,transform.rotation);
            p.GetComponent<Rigidbody>().velocity=transform.forward*v;
            //dopki nie oprogramujemy eksplozji
            //usu obiekt pocisku po 3.5 sekundzie
            Destroy(p,3.5f);
            //pokaz dym wystrzalu
            GameObject d= Instantiate(praefabDymWystrzalu, transform.position, transform.rotation);
            Destroy(d, 1.5f);
        }
    }
}
