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


public class ShootingCannon : MonoBehaviour
{
    public bool shootingRight;
    public bool triggeranimate;
    public GameObject shootingObject;
    public Transform spawnLocation;
    public TextMeshPro counter;
    public int countdowntimer;
    int countdown;

    private void Start()
    {
        countdown = countdowntimer;
    }
    private void Update()
    {
        counter.text = countdown.ToString();
    }

    public void Animate()
    {
        countdown--;
        if (countdown == 0){
            GameObject shot = Instantiate(shootingObject, spawnLocation.position, Quaternion.identity);
            if (shootingRight == true)
            {
                shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * -500);
            }
            else
            {
                shot.GetComponent<Rigidbody>().AddForce(shot.transform.forward * 500);
            }
            countdown = countdowntimer;
        }
    }
}
