[SerializeField] GameObject explosion; // эффект взрыва
private AudioSource Sound;
private Transform startPos; // позиция пула
void Start()
{
Sound = gameObject.GetComponent<AudioSource>();
startPos = gameObject.transform.parent.GetComponent<Transform>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
Sound.Play();
var exp = Instantiate(explosion, gameObject.transform.position, gameObject.transform.rotation);
Destroy(exp, 0.5f);
transform.position = startPos.position;
Invoke("ActiveFalse", 1f);
}
}
private void ActiveFalse()
{
gameObject.SetActive(false);
}