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

public class GunScript : MonoBehaviour
{
    public GameObject projectilePrefab;
    public Transform spawn_position;
    public float thrust = 1.0f;
    public AudioSource mAudio;

    // Start is called before the first frame update
    void Start()
    {
        mAudio = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        // if (Input.GetMouseButtonDown(0))
        // {
        //     SpawnProjectile();
        // }

        if (Input.GetButtonDown("Shoot"))
        {
            mAudio.Play();
            SpawnProjectile();   
        }
    }

    void SpawnProjectile(){

        //Debug.Log("SpawnProjectile");

        GameObject instance = Instantiate(projectilePrefab,spawn_position.position,Quaternion.identity);
        
        
        SphericalProjectileScript projectile = instance.GetComponent<SphericalProjectileScript>();
        projectile.dir = (spawn_position.forward * thrust);
        projectile.starting_height = spawn_position.position.magnitude;

        // Rigidbody rb = instance.GetComponent<Rigidbody>();
        // rb.velocity=(spawn_position.forward * thrust);

    }
}
