Objects are not getting destroyed [I fixed on my own]
I have tried a LOT of different methods to destroy the objects but it doesn't work. Help, please.
void Effect() { Instantiate(BulletTrailPrefab, firePoint.position, firePoint.rotation); Transform clone = Instantiate(MuzzleFlashPrefab, firePoint.position, firePoint.rotation) as Transform; clone.parent = firePoint; float size = Random.Range(0.6f, 0.9f); clone.localScale = new Vector3(size, size, size); Destroy(clone.gameObject, 0.02f); }
whats your problem? the clone object is not being destroyed? any errors information? the bullettrailprefab object you create doesnt need to be destroyed?
Yeah, sorry for not clearing it up, so the problem is that the prefabs are not deleting/removing when I want it to, otherwise, the prefabs are spawning in and it works fine.
You should then remove the bullettrailprefab object too
GameObject _object = Instantiate(BulletTrailPrefab, firePoint.position, firePoint.rotation);
Destroy(_object, delay);
Answer by SuXuK · Jan 15, 2019 at 09:43 AM
void Effect()
{
Instantiate(BulletTrailPrefab, firePoint.position, firePoint.rotation);
Transform clone = Instantiate(MuzzleFlashPrefab, firePoint.position, firePoint.rotation) as Transform;
clone.parent = firePoint;
float size = Random.Range(0.6f, 0.9f);
clone.localScale = new Vector3(size, size, size);
Destroy(clone.gameObject, 0.02f);
}