private void DestroyAfterTime() { if (hitPrefab != null) { var hitVFX = Instantiate(hitPrefab, transform.position, Quaternion.Euler(0, 0, 0)); hitVFX.transform.GetChild(4).GetComponent <Transform>().transform.rotation = Quaternion.Euler(0, 0, bossAi.GetRandomRotation()); bossAi.hasHit = true; var psHit = hitVFX.GetComponent <ParticleSystem>(); if (psHit != null) { Destroy(hitVFX, psHit.main.duration); } else { var psChild = hitVFX.transform.GetChild(0).GetComponent <ParticleSystem>(); Destroy(hitVFX, psChild.main.duration); } } Vector3 lastKnownPosition = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z); bossAi.gooProjectiles.Add(lastKnownPosition); Destroy(gameObject); }