using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class Bullet : MonoBehaviour
{
public List<AudioClip> Gunshots;
public GameObject Enemy;
public Transform EnemySpawn;
void Start()
{
// goes thru list of gunshot audios & random plays them
AudioSource sfx = GetComponent<AudioSource>();
sfx.clip = Gunshots[Random.Range(0, Gunshots.Count)];
sfx.Play();
}
void Update()
{
if(transform.position.y < -2)
{
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider other)
{
if(other.name == "Enemy")
{
Destroy(gameObject);
other.gameObject.SetActive(false); // banishing the enemy but theyre sitll in the game
StartCoroutine(RespawnEnemy(other.gameObject));
}
else if (other.name == "BoxBox")
{
Rigidbody rb = other.gameObject.GetComponent<Rigidbody>();
if (rb == null)
{
rb = other.gameObject.AddComponent<Rigidbody>();
}
}
}
private IEnumerator RespawnEnemy(GameObject Enemy)
{
yield return new WaitForSeconds(5f);
Enemy.transform.position = EnemySpawn.position;
Enemy.SetActive(true);
}
}